accuracy = historyhistoryaccuracytest_accuracy = historyhistoryval_accuracyloss = historyhistorylosstest_loss = historyhistoryval_lossepochs_range = range10pltfigurefigsize=50 5pltsubplot1 2 1pltplote
accuracy = history.history["accuracy"]: 从history对象中获取训练集准确率列表并赋值给accuracy变量。test_accuracy = history.history["val_accuracy"]: 从history对象中获取验证集准确率列表并赋值给test_accuracy变量。loss = history.history["loss"]: 从history对象中获取训练集损失列表并赋值给loss变量。test_loss = history.history["val_loss"]: 从history对象中获取验证集损失列表并赋值给test_loss变量。epochs_range = range(10): 创建一个包含 0 到 9 的整数范围,用于表示训练轮次。plt.figure(figsize=(50, 5)): 创建一个图形对象,设置图形大小为 50x5。plt.subplot(1, 2, 1): 在图形对象中创建一个 1 行 2 列的子图,并选择第一个子图作为当前子图。plt.plot(epochs_range, accuracy, label="Training Acc"): 在当前子图中绘制训练集准确率曲线,使用epochs_range作为 x 轴,accuracy作为 y 轴,设置标签为 "Training Acc"。plt.plot(epochs_range, test_accuracy, label="Test Acc"): 在当前子图中绘制验证集准确率曲线,使用epochs_range作为 x 轴,test_accuracy作为 y 轴,设置标签为 "Test Acc"。plt.legend(): 显示曲线标签。plt.title("Training and Test Acc"): 设置子图标题为 "Training and Test Acc"。plt.subplot(1, 2, 2): 在图形对象中创建一个 1 行 2 列的子图,并选择第二个子图作为当前子图。plt.plot(epochs_range, loss, label="Training loss"): 在当前子图中绘制训练集损失曲线,使用epochs_range作为 x 轴,loss作为 y 轴,设置标签为 "Training loss"。plt.plot(epochs_range, test_loss, label="Test loss"): 在当前子图中绘制验证集损失曲线,使用epochs_range作为 x 轴,test_loss作为 y 轴,设置标签为 "Test loss"。plt.legend(): 显示曲线标签。plt.title("Training and Test loss"): 设置子图标题为 "Training and Test loss"。plt.show(): 显示图形
原文地址: https://www.cveoy.top/t/topic/fQ2D 著作权归作者所有。请勿转载和采集!