此链接有一个教程,演示如何按 epoch 绘制测试和训练数据的不同指标。请检查输出plot_metrics(baseline_history)
我只有两个指标要打印,我复制了绘图部分,需要下面的帮助
如何将测试线的颜色更改为红色?我试过,但得到错误plt.plot(history.epoch, history.history['val_'+metric],
color=colors['r'], linestyle="--", label='Val')
TypeError: list indices must be integers or slices, not str
如何保证背景通俗。由于某种原因,我得到了带有白线的灰色背景
我的代码和输出如下
#plotting
def plot_metrics(history):
metrics = ['loss','acc']
for n, metric in enumerate(metrics):
name = metric.replace("_"," ").capitalize()
plt.subplot(2,2,n+1)
plt.plot(history.epoch, history.history[metric], color=colors[0], label='Train')
plt.plot(history.epoch, history.history['val_'+metric],
color=colors[9], linestyle="--", label='Val')
plt.xlabel('Epoch')
plt.ylabel(name)
if metric == 'loss':
plt.ylim([0, plt.ylim()[1]])
elif metric == 'auc':
plt.ylim([0.8,1])
else:
plt.ylim([0,1])
plt.legend()
import matplotlib.pyplot as plt
colors = plt.rcParams['axes.prop_cycle'].by_key()['color']
import matplotlib as mpl
mpl.rcParams['figure.figsize'] = (20, 12)
plot_metrics(final_model)#where abcde is fit call
哆啦的时光机
相关分类