Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 请帮助我,我可以';似乎无法修复此错误:ValueError:x和y必须具有相同的第一维度,但具有形状(10)和(1)_Python_Matplotlib_Machine Learning - Fatal编程技术网

Python 请帮助我,我可以';似乎无法修复此错误:ValueError:x和y必须具有相同的第一维度,但具有形状(10)和(1)

Python 请帮助我,我可以';似乎无法修复此错误:ValueError:x和y必须具有相同的第一维度,但具有形状(10)和(1),python,matplotlib,machine-learning,Python,Matplotlib,Machine Learning,我试图画出我的机器学习模型图,但我不断得到一个错误,说 ValueError: x and y must have same first dimension, but have shapes (10,) and (1,) 我怎样才能解决这个问题 我的代码如下: val_accuracy = history.history['val_accuracy'] loss = history.history['loss'] val_loss = history.history['val_loss']

我试图画出我的机器学习模型图,但我不断得到一个错误,说

ValueError: x and y must have same first dimension, but have shapes (10,) and (1,)
我怎样才能解决这个问题

我的代码如下:

val_accuracy = history.history['val_accuracy']
loss = history.history['loss']
val_loss = history.history['val_loss']

epochs = range(len(accuracy))
plt.figure(figsize=(18,12))
plt.plot(epochs, accuracy, 'bo', label='Training accuracy')
plt.plot(epochs, val_accuracy, 'r', label='Validation accuracy')
plt.title('Training & Validation accuracy')
plt.legend()

plt.figure(figsize=(18,12))
plt.plot(epochs, loss, 'bo', label='Training loss')
plt.plot(epochs, val_loss, 'r', label='Validation loss')
plt.title('Training & Validation loss')
plt.legend()

plt.show()

如果不访问您的
history.history
数据,很难进行诊断。但是,您可以通过打印出要绘制的每个数组的长度来开始调试问题——似乎至少有一个数组只有一个数据点。i、 例如,
print(len(epochs)、len(accurity)、len(valu-accurity)、len(valu-loss))
。哪一行引起了错误?