from sklearn import datasets
from sklearn import tree
from sklearn.metrics import classification_report
from sklearn.model_selection import train_test_split
tree = tree.DecisionTreeClassifier(criterion= 'entropy')
iris = datasets.load_iris()
X=iris.data
Y=iris.target
x_train, x_test, y_train,y_test=train_test_split(X,Y,test_size=0.3,random_state=0)
print ("The iris target names: %s"% (iris.target_names))
tree.fit(x_train, y_train)
print("决策树模型训练集的准确率:%.3f" %tree.score(x_train, y_train))
print('决策树模型测试集的谁确率:% 3f' %tree.score(x_test,y_test))
target_names = ['setosa','versicolor','virginica']
y_hat = tree.predict(x_test)
print(classification_report(y_test, y_hat, target_names = target_names))
数据科学导论 决策树分类模型
最新推荐文章于 2025-11-29 22:41:10 发布
本文展示了如何使用Python的scikit-learn库对Iris数据集进行决策树分类,包括数据预处理、模型训练、测试集评估和性能报告生成。
3737

被折叠的 条评论
为什么被折叠?



