输出结果
1、xgboost(num_trees=0): Binary prediction based on Mushroom Dataset
2、xgboost(num_trees=1): Binary prediction based on Mushroom Dataset
3、xgboost(num_trees=1,max_depth=4): Binary prediction based on Mushroom Dataset
设计思路
数据集:Dataset之mushroom:mushroom蘑菇数据集的简介、下载、使用方法之详细攻略
https://blog.csdn.net/qq_41185868/article/details/90480700
核心代码
preds = bst.predict(dtest)
predictions = [round(value) for value in preds]
test_accuracy = accuracy_score(y_test, predictions)
print("Test Accuracy: %.2f%%" % (test_accuracy * 100.0))
from matplotlib import pyplot
import graphviz
# num_trees=0
# xgb.plot_tree(bst, num_trees=0, rankdir= 'LR' )
#xgb.to_graphviz(bst,num_trees=0)
# num_trees=1
xgb.plot_tree(bst,num_trees=1, rankdir= 'LR' )
#xgb.to_graphviz(bst,num_trees=1)