如何解决Scikit 分类对比
我比较了 6 个分类的测试集的结果,得到了准确率最高的随机森林和最低的 NB ..
但是当我做评估矩阵“F1,精度和召回率”时,我得到了 NB 中的最高值..
这是正常的还是我做错了什么?
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 举报,一经查实,本站将立刻删除。