我正在使用Keras,我想使用logloss作为培训指标。我怎么把它传递到我的模型中?
我的代码如下:
model = Sequential()
model.add(Dense(output_dim=1000, input_dim=390, init='uniform'))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=500, input_dim=1000, init="lecun_uniform"))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=10, input_dim=300, init="lecun_uniform"))
model.add(Activation("sigmoid"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=200, input_dim=10, init="lecun_uniform"))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=100, input_dim=200, init ="glorot_normal"))
model.add(Activation("relu"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=50, input_dim=100, init ="he_normal"))
model.add(Activation("sigmoid"))
model.add(Dropout(0.5))
model.add(Dense(output_dim=2, input_dim=50, init = "normal"))
model.add(Activation("softmax"))
model.compile(loss='binary_crossentropy',optimizer='rmsprop', metrics=['accuracy'])
model.fit(train.values, y1, nb_epoch=10,
batch_size=50000, verbose=2,validation_split=0.3, class_weight={1:0.96, 0:0.04})
proba = model.predict_proba(train.values)
log_loss(y, proba[:,1])
如何通过log_loss代替准确性?
答案 0 :(得分:23)
您已经:loss='binary_crossentropy'
指定您的模型应优化二进制分类的日志丢失。 metrics=['accuracy']
指定应打印精度,但默认情况下也会打印出日志丢失。