train_auc = []
cv_auc = []
alpha_values = [1,2,3,4,5,10]
for alpha in alpha_values:
model = MultinomialNB(alpha = alpha)
model.fit(X_tr_bow,Y_train)
y_tr_prob = batch_predict(model,X_tr_bow)
y_cr_prob =batch_predict(model, X_cr_bow)
train_auc.append(roc_auc_score(Y_train,y_tr_prob))
cv_auc.append(roc_auc_score(Y_cv,y_cr_prob))
plt.plot(alpha, train_auc, label='Train AUC')
plt.plot(alpha, cv_auc, label='CV AUC')
plt.scatter(alpha, train_auc, label='Train AUC points')
plt.scatter(alpha, cv_auc, label='CV AUC points')
plt.legend()
plt.xlabel("alpha: hyperparameter")
plt.ylabel("roc_AUC_score")
plt.title("Roc_Auc score PLOTS")
plt.grid()
plt.show()
此代码显示错误x和y必须具有相同的第一维,但形状为(1,)和(6,)
答案 0 :(得分:1)
问题是您要绘制一个带有列表的y值的单个值alpha
。您需要使用完整的x值。在所有绘图命令中将alpha
替换为alpha_values
plt.plot(alpha_values, train_auc, label='Train AUC')
plt.plot(alpha_values, cv_auc, label='CV AUC')
plt.scatter(alpha_values, train_auc, label='Train AUC points')
plt.scatter(alpha_values, cv_auc, label='CV AUC points')