'Path that leads to the predicted answer in Big Decision Tree
My goal is to figure out why the decision tree predicted value is computed. As below, when features [5.1 3.5 1.4 0.2] then the predicted value is [0]. When tree is simple I can easily figure out using the text representation of tree. However, when there are many features in dataset and the tree become big, tree diagram become hard to read. Is there a tool that tells the path why the predicted value was calculated that way?
from matplotlib import pyplot as plt
from sklearn import datasets
from sklearn.tree import DecisionTreeClassifier
from sklearn import tree
iris = datasets.load_iris()
X = iris.data
y = iris.target
fit = DecisionTreeClassifier(random_state=1234).fit(X,y)
print('--> when ', X[0], 'then ', fit.predict([X[0]])) # --> when [5.1 3.5 1.4 0.2] then [0]
# Is there a function that tells the path why the predicted value was calculated that way?
text_representation = tree.export_text(fit) # when tree is small, I can figure why the prediction is
print('Graph')
print(text_representation)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
