【发布时间】:2018-11-18 23:59:44
【问题描述】:
当我使用代码时
import numpy as np
y_test = np.asarray(y_test)
misclassified = np.where(y_test != clf.predict(X_test))
对于二进制和 3 路分类,我们得到一个 2 元组,它是 X_test 的一长串索引(我假设)。两个元组中的每一个中的这些索引/数字也有重复。有人能解释一下错误分类应该是什么样子吗?
当我使用代码打印它时
clf=RandomForestClassifier(min_samples_leaf=20);
model=clf.fit(X_train,y_train);
#rf=RandomForestRegressor();
accu=clf.score(x_test,y_test);
pred=clf.predict(x_test);
cnf_matrix=confusion_matrix(y_test,pred);
print("Accuracy:",accu," Confusion matrix:",cnf_matrix);
##Test for false negatives
np_y_test=np.asarray(y_test);
print("test ",np_y_test.shape, " ", x_test.shape, " ",pred.shape);
miss_arr= np.where(np_y_test!=pred);
print(type(miss_arr)," mispredict ", miss_arr);
,我的看起来像这样:
Accuracy: 0.7131782945736435 Confusion matrix: [[32 0 15]
[ 5 0 17]
[ 0 0 60]]
test shape of np.array(y_test) (129, 1) shape of x_test (129, 16) shape of clf.predict(x_test) (129,)
<class 'tuple'> mispredict (array([ 0, 0, 0, ..., 128, 128, 128]), array([19, 20, 34, ..., 49, 50, 51]))
如您所愿,这是用于 3 路分类。对于 2 路分类,我也得到了类似的输出。
【问题讨论】: