Reputation: 201
I have simple Decision Tree program in Python. Is there a way to find out (print) the most influential parameter (or more of them) from X that caused the result? For example: "the predicted result is "yes". The most influential parameters are [0] values in items of X"
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)
Upvotes: 1
Views: 728
Reputation: 1868
feature_importances_
attribute can be used.
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.]
Here second feature importance is zero, it means this feature is not included in the rule tree.
Upvotes: 1