gpt4 book ai didi

python - 决策树——Python最有影响力的参数

转载 作者:太空宇宙 更新时间:2023-11-03 14:00:51 25 4
gpt4 key购买 nike

我有一个简单的 Python 决策树程序。有没有办法从 X 中找出(打印)导致结果的最有影响力的参数(或多个参数)?例如:“预测结果为"is"。最有影响的参数是X项中的[0]个值”

from sklearn import tree


X=[[100,3],[130,3],[80,2],[90,2],[140,3]]
Y=["yes","no","yes","yes","no"]

clf = tree.DecisionTreeClassifier()

clf = clf.fit(X,Y)

List1=[124,3]

prediction = clf.predict([List1])

print(prediction)

最佳答案

可以使用

feature_importances_属性。

The feature importances. The higher, the more important the feature. The importance of a feature is computed as the (normalized) total reduction of the criterion brought by that feature.

http://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html

print(clf.feature_importances_)
> [1. 0.]

这里第二个特征重要性为零,这意味着该特征不包含在规则树中。

关于python - 决策树——Python最有影响力的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49250254/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com