Reputation: 21
Just like the situation in the picture, my decision tree always has an empty block. I have already searched for a while, but still can't find the solution. My codes are listed below, running in jupyter notebook. Hoping for your help.
from sklearn import tree
from sklearn import datasets
import pydotplus
wine = datasets.load_wine()
X = wine.data
Y = wine.target
from sklearn.model_selection import train_test_split
X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size = 0.3)
clf = tree.DecisionTreeClassifier(criterion = 'gini').fit(X_train,Y_train)
clf.score(X_train,Y_train)
clf.predict(X_test)
feature_names = wine.feature_names
target_name = wine.target_names
import graphviz
dot_data = tree.export_graphviz(clf,
out_file = None,
feature_names = feature_na,
class_names = target_name,
filled = None,
rounded = True,)
dot_data = dot_data.replace('helvetica', 'Microsoft JhengHei')
graph = pydotplus.graph_from_dot_data(dot_data)
graph.write_pdf('wine.pdf')
Upvotes: 2
Views: 494
Reputation: 91
I think there is a very high chance that your package manager messed up. Have you used pip to install the packages? Try installing via conda (I recommend creating conda virtual environment).
Also I think you have a typo at line 24: feature_names = feature_na(mes). By installing packages via conda + fixing the typo and running your code I got the following tree.
Upvotes: 1