Python Forum
Classification and Regression tree (CART)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Classification and Regression tree (CART)
#1
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')
Error:
--------------------------------------------------------------------------- InvocationException Traceback (most recent call last) <ipython-input-17-5ddeb7a2766f> in <module> 3 class_names=['0','1']) 4 graph=pydotplus.graph_from_dot_data(dot_data.getvalue()) ----> 5 graph.write_png('buys_computer.png') C:\ProgramData\Anaconda3\lib\site-packages\pydotplus\graphviz.py in <lambda>(path, f, prog) 1808 lambda path, 1809 f=frmt, -> 1810 prog=self.prog: self.write(path, format=f, prog=prog) 1811 ) 1812 C:\ProgramData\Anaconda3\lib\site-packages\pydotplus\graphviz.py in write(self, path, prog, format) 1916 1917 else: -> 1918 fobj.write(self.create(prog, format)) 1919 finally: 1920 if close: C:\ProgramData\Anaconda3\lib\site-packages\pydotplus\graphviz.py in create(self, prog, format) 1958 if self.progs is None: 1959 raise InvocationException( -> 1960 'GraphViz\'s executables not found') 1961 1962 if prog not in self.progs: InvocationException: GraphViz's executables not found
Please help in short out above issue
Reply
#2
Can u please support to resolve the above program error
Reply
#3
Have you installed and imported GraphViz? https://pypi.org/project/graphviz/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Sad Miss-Classification problem with shuffled batch Faebs94 0 1,527 Sep-02-2021, 11:55 AM
Last Post: Faebs94
  Probabilities of binary classification problem Troublesome1996 0 2,398 Apr-19-2021, 06:40 PM
Last Post: Troublesome1996
  GridSearchCV for multi-label classification mapypy 0 3,648 Mar-29-2021, 01:58 AM
Last Post: mapypy
  GNN For Graph "Classification" BennyS 1 1,760 Feb-09-2021, 12:09 PM
Last Post: BennyS
  Help with multiclass classification in perceptron code Nimo_47 0 3,702 Nov-09-2020, 10:32 PM
Last Post: Nimo_47
  Classification of Request PythonLearner703 8 3,886 Dec-09-2019, 08:56 PM
Last Post: micseydel
  CNN Speech Classification Mitchie87 0 1,583 Dec-06-2019, 06:17 PM
Last Post: Mitchie87
  Keras: Time series classification midarq 0 1,965 Sep-25-2019, 09:03 AM
Last Post: midarq
  Classification with shuffling PythonNewbie 1 2,393 Nov-12-2017, 10:23 AM
Last Post: PythonNewbie

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020