首页 > 解决方案 > Keras 对数损失函数

问题描述

我必须对 keras 应用以下损失函数:

在此处输入图像描述

这是我的代码:

input_shape = self.s_dim[1:]
input_ = Input(shape=input_shape, name='input')
hidden = Dense(self.n_hidden, activation='relu')(input_)
out = Dense(3, activation='sigmoid')(hidden)

model = Model(inputs=input_, outputs=out, name="ar-model")
model.compile(loss='mean_squared_logarithmic_error', optimizer=SGD(lr=self.lr_ar))
return model

损失函数mean_squared_logarithmic_error适合这里吗?

标签: machine-learningneural-networkkerasloss-function

解决方案


mean_squared_logarithmic_error 与对数损失不同,这正是您要寻找的。对数损失与交叉熵相同。您可以使用 binary_crossentropy 或 categorical_crossentropy,具体取决于您的输出。


推荐阅读