Accuracy score of a Decision Tree Classifier
13,530
The problem is that you are mixing up things. It doesn't mean anything to compute the accuracy comparing the train and test labels.
Do the following instead:
features_train, labels_train, features_test, labels_test = makeTerrainData()
X = features_train
Y = labels_train
clf = DecisionTreeClassifier()
clf = clf.fit(X,Y)
# Here call it somehing else!
yhat_test = clf.predict(features_test)
# Compute accuracy based on test samples
acc = accuracy_score(labels_test, yhat_test)
Related videos on Youtube
Author by
MaverickEyedea
Updated on June 04, 2022Comments
-
MaverickEyedea almost 2 years
import sys from class_vis import prettyPicture from prep_terrain_data import makeTerrainData from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import accuracy_score import numpy as np import pylab as pl features_train, labels_train, features_test, labels_test = makeTerrainData() X = features_train Y = labels_train clf = DecisionTreeClassifier() clf = clf.fit(X,Y) labels_test = clf.predict(features_test) acc = accuracy_score(labels_test, labels_train)
I can't calculate the accuracy of a DecisionTreeClassifier using the above code. Can somebody help me with this?
-
Shridhar R Kulkarni about 6 yearsMentioning error here will help.
-
MMF about 6 yearsWell, it doesn't mean anything to compute the accuracy by comparing the labels of the test and the train, first, they are not related and second you most probably don't even have the same length for both! Your problem is that you overwrite the name labels_test, call it something else
-
-
user269867 almost 6 yearsglobal name 'accuracy_score' is not defined
-
taga almost 5 yearsI get the error
ValueError: labels_test and yhat_test have different number of output (2!=1)
-
taga almost 5 yearsIs there any way that you can help me with this? stackoverflow.com/questions/56622349/…