二元交叉熵与分类交叉熵
我有一个包含 10 个分类特征和一个 0 类和 1 类输出特征的数据集。X_train 遵循 3D 数组,因此我事先对数据集进行了标签编码。 我已经应用了 categorical_crossentropy,但使用 sigmoid 激活函数得到了 26% 的准确率。当我应用binary_crossentropy时,准确率大幅提高到98%。
model = Sequential()
model.add(LSTM(256, input_shape=(n_timesteps,n_features),recurrent_activation='hard_sigmoid'))
model.add(Dense(16))
model.add(Dense(n_outputs, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
数据集分为:
X_train: (430000, 5, 10)
y_train: (430000, 1)
我很困惑我是否在做正确的事情。请推荐!!
I have a dataset with 10 categorical features and one output feature with class 0 and 1. X_train follows a 3D array so I have done label encoding beforehand on the dataset.
I have applied categorical_crossentrophy but I am getting 26% accuracy with activation function sigmoid. When I apply binary_crossentrophy, the accuracy drastically increased to 98%.
model = Sequential()
model.add(LSTM(256, input_shape=(n_timesteps,n_features),recurrent_activation='hard_sigmoid'))
model.add(Dense(16))
model.add(Dense(n_outputs, activation='sigmoid'))
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
and dataset is divided as:
X_train: (430000, 5, 10)
y_train: (430000, 1)
I am confused if I am doing the right thing. Please suggest!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想预测 10 个不同的类别,则需要使用 categorical_crossentropy。最终输出层必须有 10 个带有 softmax 激活函数的单元。 binary_crossentropy 用于二元分类,例如猫和狗,或者是或否。
If you want to predict 10 different classes, you will need to use the categorical_crossentropy. The final output layer must have 10 units with the softmax activation function. The binary_crossentrophy is for binary classification like cat and dog, or yes or no.