收藏   订阅   蔚来影讯
你现在的位置:首页 » 业余爱好 » 正文

在训练模型model.compile()中计算loss的常用函数都有哪些?

时间:2019年09月17日 09:48:28 | 作者 :老马 | 分类 : 业余爱好 | 浏览:2982 | 评论:0

loss是训练模型的一个重要参数,用来计算预测与真实label的均方误差

model.compile(loss='mean_squared_error', optimizer='sgd')
from keras import losses
model.compile(loss=losses.mean_squared_error, optimizer='sgd')

以上是两种使用语法,可以传递函数名称给loss 也可以传递函数式 给loss 。

mean_squared_error

mean_squared_error(y_true, y_pred)

mean_absolute_error

mean_absolute_error(y_true, y_pred)

mean_absolute_percentage_error

mean_absolute_percentage_error(y_true, y_pred)

mean_squared_logarithmic_error

mean_squared_logarithmic_error(y_true, y_pred)

squared_hinge

squared_hinge(y_true, y_pred)

hinge

hinge(y_true, y_pred)

categorical_hinge

categorical_hinge(y_true, y_pred)

logcosh

logcosh(y_true, y_pred)

预测误差的双曲余弦的对数。

对于小的 xlog(cosh(x)) 近似等于 (x ** 2) / 2。对于大的 x,近似于 abs(x) - log(2)。这表示 'logcosh' 与均方误差大致相同,但是不会受到偶尔疯狂的错误预测的强烈影响。

参数

  • y_true: 目标真实值的张量。

  • y_pred: 目标预测值的张量。

返回

每个样本都有一个标量损失的张量。


categorical_crossentropy

categorical_crossentropy(y_true, y_pred)

sparse_categorical_crossentropy

sparse_categorical_crossentropy(y_true, y_pred)

binary_crossentropy

binary_crossentropy(y_true, y_pred)

kullback_leibler_divergence

kullback_leibler_divergence(y_true, y_pred)

poisson

poisson(y_true, y_pred)

cosine_proximity

cosine_proximity(y_true, y_pred)

注意: 当使用 categorical_crossentropy 损失时,你的目标值应该是分类格式 (即,如果你有 10 个类,每个样本的目标值应该是一个 10 维的向量,这个向量除了表示类别的那个索引为 1,其他均为 0)。 为了将 整数目标值 转换为 分类目标值,你可以使用 Keras 实用函数 to_categorical

from keras.utils.np_utils import to_categorical

categorical_labels = to_categorical(int_labels, num_classes=None)

 以上方法来自官方文档

上一篇:model.Sequetial()函数添加激活函数层layers的两种方法 下一篇:域名投资ifunvr.cn 域名转让
本站致力于揭露全国影视投资诈骗案件 避免更多老百姓受骗上当
经历分享 请投稿

网络世界,不加微信QQ手机,留言沟通

发表评论

必填

回复后邮件通知

客服会联系您

◎欢迎参与讨论,聆听心声,下滑更多影视投资诈骗相关内容。

栏目
文章归档
标签列表