我需要帮助来构建用于分类的 keras 模型。 我有
输入:167个光谱点
输出 11 类研究物质。
但是在一个数据集中可以是具有多种物质的物质幽灵(例如包含2、3、4类)。
我尝试使用categorical_crossentropy
,但它仅适用于非相交类。
KerasDoc :
Note: when using the categorical_crossentropy loss, your targets should be in categorical format (e.g. if you have 10 classes, the target for each sample should be a 10-dimensional vector that is all-zeros expect for a 1 at the index corresponding to the class of the sample). In order to convert integer targets into categorical targets, you can use the Keras utility to_categorical:
我的代码:
model = Sequential()
model.add(Dense(64, input_dim=167))
model.add(Dense(32))
model.add(Dense(11))
model.add(Activation('sigmoid'))
model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
我尝试了很多模型,但都没有得到好的结果。
最佳答案
您可能应该很好地使用 sigmoid
和 binary_crossentropy
( See here )
PS:这不是您的情况,但对于 categorial_crossentropy
,您最好使用 softmax
激活。 softmax 输出经过优化以仅最大化一类的东西。
(如果有人想用一个好的或更好的“优化器”来补充这个答案,请随意)。
关于machine-learning - Keras分类模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44163621/