比较不同型号的精度

时间:2019-02-24 23:08:19

标签: python-3.x matplotlib plot scikit-learn

我正在尝试构建一种方法来绘制不同ML模型(例如

)的准确性
from sklearn import model_selection
from sklearn.linear_model import LogisticRegression
from sklearn.tree import DecisionTreeClassifier
from sklearn.neighbors import KNeighborsClassifier

我已使用此代码,但无法获得条形图

#Evaluating performance
results = []
names = []
scoring = 'accuracy'

for name, model in models:
    kfold = model_selection.KFold(n_splits=10, random_state=0)
    cv_results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
    results.append(cv_results)
    names.append(name)
    msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())
    results.append(cv_results.mean())
    print(msg)

plt.plot(cv_results) plots a line graph

我正在尝试绘制X轴(不同模型)Y轴(精度)的条形图

1 个答案:

答案 0 :(得分:0)

plt.plot将按照您的指示绘制线条。您需要的是plt.bar,它将绘制一个小节图。假设模型的名称存储在列表names中,准确度存储在列表results中,就像您的代码片段一样,则应该这样做:

plt.bar(names,results)