x 和 y 必须具有相同的第一个维度,但形状分别为 (9,) 和 (4,)。

huangapple go评论133阅读模式
英文:

x and y must have same first dimension, but have shapes (9,) and (4,)

问题

y_pred = fig.predict(x.reshape(1, -1)).reshape(-1)
colors_dark = ["#1F1F1F", "#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_loss1 = 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()
英文:
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()

This is my code. But when i execute it, it says that x and y must have first dimension but have shapes 9 and 4. Please help me !!!! any help would be appreciated

答案1

得分: 0

无论错误出现在哪一行,你都试图绘制两个长度不同的列表,具体为9和4。列表epochs,你在绘图时用作x轴数组,长度为9。这意味着train_acc1train_loss1val_acc1val_loss1中的一个列表长度为4。当你遇到错误时,请查看出错的行数,看你正在尝试在其中绘制哪个列表。然后,不要将epoch作为x轴数组,尝试使用长度为4的其他内容,比如[0,1,2,3]。我怀疑你可能会在另一行再次遇到这个错误,所以请按照相同的步骤处理。希望对你有所帮助。

英文:

At whatever line the error is in you are trying to plot 2 lists with different lengths specifically 9,4. The list epochs, that you use as x_array whenever you plot something, has length 9. So it means that one of the lists train_acc1, train_loss1, val_acc1, val_loss1 has length of 4. When you get the error see at which line it is and see which of those lists you are trying to plot there.
Then instead of having the epoch as the x_array try something with a length of 4 like [0,1,2,3]. I suspect you might get this error again in another line so follow the same process. Hope this helps.

huangapple
  • 本文由 发表于 2023年3月8日 14:42:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75670048.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定