微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Scikit 分类对比

如何解决Scikit 分类对比

我比较了 6 个分类的测试集的结果,得到了准确率最高的随机森林和最低的 NB ..

enter image description here

但是当我做评估矩阵“F1,精度和召回率”时,我得到了 NB 中的最高值..

这是正常的还是我做错了什么?

enter image description here

我使用相同的代码来计算每个分类的指标:

RFclf=RandomForestClassifier(n_estimators=20)
#Train the model using the training sets y_pred=clf.predict(X_test)
RFclf.fit(X_train,y_train)
train_pred=RFclf.predict(X_train)
test_pred=RFclf.predict(X_test)

rftrain = metrics.accuracy_score(y_train,train_pred)
rftest = metrics.accuracy_score(y_test,test_pred)

print("Accuracy for Random Forest Test data on the test set: ",rftest)    
frftest = f1_score(y_test,test_pred) 
prftest = precision_score(y_test,test_pred) 
rrftest = recall_score(y_test,test_pred)

并使用此代码进行绘图:

plt.figure(figsize=(14,7))
ax = plt.subplot(111)

models = ['SVM ','NB','Decision Tree ','LR','KNN','RF']
values = [pSVMtest,pGAcc,pdesicionT,pLRAcc,pKNAcc,prftest]
model = np.arange(len(models))

plt.bar(model+0.15,values,align='center',width = 0.15,alpha=0.7,color = 'blue',label =         
'precision')
plt.xticks(model,models)



ax = plt.subplot(111)

models = ['SVM ','RF']
values = [rSVMtest,rGAcc,rdesicionT,rLRAcc,rKNAcc,rrftest]
model = np.arange(len(models))

plt.bar(model+0.3,color = 'green',label =         
'recall')
plt.xticks(model,models)

ax = plt.subplot(111)

models = ['SVM ','RF']
values = [fSVMtest,fGAcc,fdesicionT,fLRAcc,fKNAcc,frftest]
model = np.arange(len(models))


plt.bar(model+0.45,color = 'red',label =     
'F1 score')
plt.xticks(model,models)



plt.ylabel('Performance Metrics for Different models')
plt.title('Model')

# removing the axis on the top and right of the plot window
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
ax.legend()

plt.show()    

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?