【发布时间】:2018-04-25 09:12:17
【问题描述】:
我有一个带有 Scikit-Learn 的基本决策树分类器:
#Used to determine men from women based on height and shoe size
from sklearn import tree
#height and shoe size
X = [[65,9],[67,7],[70,11],[62,6],[60,7],[72,13],[66,10],[67,7.5]]
Y=["male","female","male","female","female","male","male","female"]
#creating a decision tree
clf = tree.DecisionTreeClassifier()
#fitting the data to the tree
clf.fit(X, Y)
#predicting the gender based on a prediction
prediction = clf.predict([68,9])
#print the predicted gender
print(prediction)
当我运行程序时,它总是输出“男性”或“女性”,但我如何才能看到预测为男性或女性的概率?例如,上面的预测返回“男性”,但我如何让它打印预测为男性的概率?
谢谢!
【问题讨论】:
-
如答案所述,您可以使用
predict_proba,但请注意概率不是很好:rpmcruz.github.io/machine%20learning/2018/02/09/… -
“不是很好”是轻描淡写的。因为您使用的是决策树,所以每个样本都在“男性”分支或“女性”分支中。所以概率永远是 1。
标签: python machine-learning scikit-learn classification decision-tree