如何绘制一个keras实验的学习曲线? [英] How to plot a learning curve for a keras experiment?

查看:679
本文介绍了如何绘制一个keras实验的学习曲线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用keras训练RNN,并想了解验证准确性如何随数据集大小而变化. Keras的历史记录对象中有一个名为val_acc的列表,该列表会在每个纪元后以相应的验证集准确性(

I'm training an RNN using keras and would like to see how the validation accuracy changes with the data set size. Keras has a list called val_acc in its history object which gets appended after every epoch with the respective validation set accuracy (link to the post in google group). I want to get the average of val_acc for the number of epochs run and plot that against the respective data set size.

问题:如何获取val_acc列表中的元素并执行类似numpy.mean(val_acc)的操作?

Question: How can I retrieve the elements in the val_acc list and perform an operation like numpy.mean(val_acc)?

编辑:正如@runDOSrun所说,获取val_acc的均值没有意义.让我集中精力获取最终的val_acc.

As @runDOSrun said, getting the mean of the val_accs doesn't make sense. Let me focus on getting the final val_acc.

我尝试了@nemo的建议,但是没有运气.这是我打印时得到的

I tried what's been suggested by @nemo but no luck. Here's what I got when I print

model.fit(X_train, y_train, batch_size = 512, nb_epoch = 5, validation_split = 0.05).__dict__

输出:

{'model': <keras.models.Sequential object at 0x000000001F752A90>, 'params': {'verbose': 1, 'nb_epoch': 5, 'batch_size': 512, 'metrics': ['loss', 'val_loss'], 'nb_sample': 1710, 'do_validation': True}, 'epoch': [0, 1, 2, 3, 4], 'history': {'loss': [0.96936064512408959, 0.66933631673890948, 0.63404161288724303, 0.62268789783555867, 0.60833334699708819], 'val_loss': [0.84040999412536621, 0.75676006078720093, 0.73714292049407959, 0.71032363176345825, 0.71341043710708618]}}

在我的历史词典中,没有列表显示为val_acc.

It turns out there's no list as val_acc in my history dictionary.

问题:如何在history词典中包含val_acc?

Question: How to include val_acc in to the history dictionary?

推荐答案

要获取精度值,您需要请求在fit期间计算它们,因为精度不是目标函数,而是(通用)度量.有时计算准确性没有意义,因此在Keras中默认情况下未启用它.但是,它是一个内置指标,很容易添加.

To get accuracy values, you need to request that they are calculated during fit, because accuracy is not an objective function, but a (common) metric. Sometimes calculating accuracy does not make sense, so it is not enabled by default in Keras. However, it is a built-in metric, and easy to add.

要添加指标,请在model.compile 中使用metrics=['accuracy']参数.

To add the metric, use metrics=['accuracy'] parameter to model.compile.

在您的示例中:

history = model.fit(X_train, y_train, batch_size = 512, 
          nb_epoch = 5, validation_split = 0.05)

然后您可以按history.history['val_acc']

这篇关于如何绘制一个keras实验的学习曲线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆