本文介绍了决策树分类器的准确性得分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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)

我无法使用以上代码来计算DecisionTreeClassifier的准确性.有人可以帮我吗?

I can't calculate the accuracy of a DecisionTreeClassifier using the above code.Can somebody help me with this?

推荐答案

问题是您正在混淆事物.对比训练标签和测试标签并不意味着计算准确性.

The problem is that you are mixing up things. It doesn't mean anything to compute the accuracy comparing the train and test labels.

请执行以下操作:

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)

这篇关于决策树分类器的准确性得分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 08:32