为什么运行这一段代码,没有生成结果 def plot_model_history(model_history): """ Plot Accuracy and Loss curves given the model_history """ fig, axs = plt.subplots(1, 2, figsize=(15, 5)) # summarize history for accuracy axs[0].plot(range(1, len(model_history.history['acc']) + 1), model_history.history['acc']) axs[0].plot(range(1, len(model_history.history['val_acc']) + 1), model_history.history['val_acc']) axs[0].set_title('Model Accuracy') axs[0].set_ylabel('Accuracy') axs[0].set_xlabel('Epoch') axs[0].set_xticks(np.arange(1, len(model_history.history['acc']) + 1), len(model_history.history['acc']) / 10) axs[0].legend(['train', 'val'], loc='best') # summarize history for loss axs[1].plot(range(1, len(model_history.history['loss']) + 1), model_history.history['loss']) axs[1].plot(range(1, len(model_history.history['val_loss']) + 1), model_history.history['val_loss']) axs[1].set_title('Model Loss') axs[1].set_ylabel('Loss') axs[1].set_xlabel('Epoch') axs[1].set_xticks(np.arange(1, len(model_history.history['loss']) + 1), len(model_history.history['loss']) / 10) axs[1].legend(['train', 'val'], loc='best') fig.savefig('plot.png') plt.show()
时间: 2023-08-10 09:07:13 浏览: 132
matlab.rar_matlab 代码生成_plot_fields MATLAB
可能是因为缺少了必要的库导入,需要导入如下库:
```python
import matplotlib.pyplot as plt
import numpy as np
```
若已经导入了这两个库,可能需要检查传入函数中的参数是否正确或存在错误。
阅读全文