0

I would like to build decision tree based on entropy for nominal data in Python but I can not do it. I know, some codes to build decision tree work for numerical data. I present my code for you, my code is as follows:

import numpy as np
from sklearn import tree
from matplotlib import pyplot as plt

X=np.array([['N30','high','no','fair'],['N30','high','no','excellent'],['3140','high','no','fair'],['L40','medium','no','fair'],['L40','low','yes','fair'],['L40','low','yes','excellent'],['3140','low','yes','excellent'],['N30','medium','no','fair'],['N30','low','yes','fair'],['L40','medium','yes','fair'],['N30','medium','yes','excellent'],['3140','medium','no','excellent'],['3140','high','yes','fair']])
y=np.array(['no','no','yes','yes','yes','no','yes','no','yes','yes','yes','yes','yes','no'])# búy_computer
#build decision tree
clf = tree.DecisionTreeClassifier(criterion='entropy', max_depth=4,min_samples_leaf=4)
#max_depth represents max level allowed in each tree, min_samples_leaf minumum samples storable in leaf node

#fit the tree to iris dataset
clf.fit(X,y)

#plot decision tree
fig, ax = plt.subplots(figsize=(6, 6)) #figsize value changes the size of plot
tree.plot_tree(clf,ax=ax,feature_names=['Age','income','Student','credit'])
plt.show()

How can I proceed?

halfer
  • 19,824
  • 17
  • 99
  • 186

0 Answers0