Classification and Regression tree (CART) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Classification and Regression tree (CART) (/thread-26930.html) |
Classification and Regression tree (CART) - kumarants - May-19-2020 import sklearn from sklearn.preprocessing import LabelEncoder import pandas as pd import numpy as np data=pd.read_excel('CART.xlsx') le_age=LabelEncoder() le_income=LabelEncoder() le_student=LabelEncoder() le_credit_rating=LabelEncoder() le_buys_computer=LabelEncoder() data['age_n']=le_age.fit_transform(data['age']) data['income_n']=le_income.fit_transform(data['income']) data['student_n']=le_student.fit_transform(data['student']) data['credit_rating_n']=le_credit_rating.fit_transform(data['credit_rating']) data['buys_computer_n']=le_credit_rating.fit_transform(data['buys_computer']) from sklearn.tree import DecisionTreeClassifier clf=DecisionTreeClassifier() dt=clf.fit(x,y) dt DecisionTreeClassifier(class_weight=None,criterion='gini',max_depth=None,max_features=None,max_leaf_nodes=None,min_impurity_decrease=0.0, min_impurity_split=None,min_samples_leaf=1,min_samples_split=2,min_weight_fraction_leaf=0.0,presort=False,random_state=None,splitter='best') from sklearn.tree import export_graphviz from sklearn.externals.six import StringIO from IPython.display import Image import pydotplus dot_data=StringIO() export_graphviz(dt,out_file=dot_data,filled=True,rounded=True,special_characters=True,feature_names=feature_cols, class_names=['0','1']) graph=pydotplus.graph_from_dot_data(dot_data.getvalue()) graph.write_png('buys_computer.png') Please help in short out above issue
RE: Classification and Regression tree (CART) - kumarants - May-26-2020 Can u please support to resolve the above program error RE: Classification and Regression tree (CART) - Larz60+ - May-26-2020 Have you installed and imported GraphViz? https://pypi.org/project/graphviz/ |