决策树分类器的准确度分数

时间:2018-03-10 03:09:48

标签: machine-learning classification decision-tree floating-accuracy

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的准确性。 有人可以帮我吗?

2 个答案:

答案 0 :(得分:2)

问题在于你是在混淆东西。与列车和测试标签相比,计算精度并不意味着什么。

请执行以下操作:

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)

答案 1 :(得分:0)

进行此更改

predicted = clf.predict(features_test)

acc =准确度得分(labels_test,已预测)