python机器学习-鸢尾花决策树
2021/10/21 11:39:40
本文主要是介绍python机器学习-鸢尾花决策树,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
决策树API
- class sklearn.tree.DecisionTreeClassifier(criterion=’gini’, max_depth=None,random_state=None)
- 决策树分类器
- criterion:默认是’gini’系数,也可以选择信息增益的熵’entropy’
- max_depth:树的深度大小
- random_state:随机数种子
- 其中会有些超参数:max_depth:树的深度大小
#鸢尾花决策树 def decision_iris(): """ 用决策树对鸢尾花进行分类 :return: """ #获取数据集 iris = load_iris() #划分数据集 x_train,x_test,y_train,y_test=train_test_split(iris.data,iris.target,random_state=22) #决策树预估器 estimator=DecisionTreeClassifier(criterion="entropy")#criterion默认为gini系数,此处选择的为信息增益的熵 #max_depth:树深的大小,random_state:随机数种子 estimator.fit(x_train,y_train) #模型评估 y_predict=estimator.predict(x_test) print("y_predict:\n",y_predict) print("直接对比真实值和预测值:\n",y_test==y_predict) score=estimator.score(x_test,y_test) print("准确率为:\n",score) #决策树可视化 export_graphviz(estimator,out_file="iris_tree.dot")
这篇关于python机器学习-鸢尾花决策树的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python