我正在尝试构建一种方法来绘制不同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轴(精度)的条形图
答案 0 :(得分:0)
plt.plot
将按照您的指示绘制线条。您需要的是plt.bar
,它将绘制一个小节图。假设模型的名称存储在列表names
中,准确度存储在列表results
中,就像您的代码片段一样,则应该这样做:
plt.bar(names,results)