y_pred = fig.predict(x.reshape(1, -1)).reshape(-1)
colors_dark = ["#1F1FIF", "#313131", "#636363", "#AEAEAE", "#DADADA"]
colors_red = ["#331313", "#582626", "#9E1717", "#D35151", "#E9B4B4"]
colors_green=[ "# 01411C", "#4B6F44", "#4F7942", "#74C365", "#D0F0C0"]
filterwarnings("ignore")
epochs =[ i for i in range(9)]
fig, ax = plt.subplots(1, 2,figsize=(14,7))
train_acc1 = model_history.history[ "accuracy" ]
train_lossl = model_history.history[ "loss"]
val_acc1 = model_history.history[ "val_accuracy" ]
val_loss1 = model_history.history[ "val_loss" ]
fig.text(s='Epochs vs. Training and Validation Accuracy/Loss',size=18,fontweight='bold',
fontname='monospace',color=colors_dark[1],y=1,x=0.28,alpha=0.8)
sns.despine()
ax[0].plot(epochs,train_acc1,marker='o',markerfacecolor=colors_green[2],color=colors_green[3],
label="Training Accuracy")
ax[0].plot(epochs, val_acc1,
marker='o',markerfacecolor=colors_red[2],color=colors_red[3],label="Validation Accuracy")
ax[0].legend(frameon=False)
ax[0].set_xlabel("Epochs")
ax[0].set_ylabel("Accuracy")
sns.despine()
ax[1].plot(epochs[:],train_loss1,marker='o',markerfacecolor=colors_green[2],
color=colors_green[3],label="Training Loss")
ax[1].plot(epochs[:],val_loss1,marker="o",markerfacecolor=colors_red[2],color=colors_red[3],
label = "Validation Loss")
ax[1].legend(frameon=False)
ax[1].set_xlabel("Epochs")
ax[1].set_ylabel("Training & Validation Loss")
fig.show()
这是我的代码。但是当我执行它的时候,它说x和y必须有第一维,但是有形状9和4。请帮助我!!!任何帮助都将不胜感激
1条答案
按热度按时间pgky5nke1#
不管错误在哪一行,您都试图绘制两个不同长度的列表,具体来说是9,4。列表
epochs
,无论何时绘制,都用作x_array,长度为9。因此,这意味着列表train_acc1
,train_loss1
,val_acc1
中的一个,val_loss1
的长度为4。当你得到错误时,看看它在哪一行,看看你试图在那里绘制的列表。然后尝试使用长度为4的东西,比如[0,1,2,3]
,而不是使用epoch作为x_array。我怀疑你可能会在另一行中再次得到这个错误,所以遵循同样的过程。希望这对你有帮助。