我有一个在Python 3中的Keras模型(Sequential):
class LossHistory(keras.callbacks.Callback):
def on_train_begin(self, logs={}):
self.matthews_correlation = []
def on_epoch_end(self, batch, logs={}):
self.matthews_correlation.append(logs.get('matthews_correlation'))
...
model.compile(loss='mean_squared_error', optimizer='adam', metrics=['matthews_correlation'])
history = LossHistory()
model.fit(Xtrain, Ytrain, nb_epoch=10, batch_size=10, callbacks=[history])
scores = model.evaluate(Xtest, Ytest, verbose=1)
...
MCC = matthews_correlation(Ytest, predictions)
model.fit()方法打印出 - 据说是根据metrics = ['matthews_correlation']部分 - 进展和Matthews Correlation Coefficient(MCC). 但它们与最终的MCC相差很大。最终的MCC函数给出了预测的整体MCC,并与sklearn的MCC函数一致(即我相信这个值)。
1) model.evaluate()的得分是什么?它们与最终的MCC或每个epoch的MCC完全不同。
2) 每个epoch的MCC是什么?看起来像这样:
Epoch 1/10 580/580 [===========] - 0s - loss: 0.2500 - matthews_correlation: -0.5817
它们是如何计算的,为什么它们与最终的MCC差别如此之大?
3) 我能否在on_epoch_train()函数中添加matthews_correlation()函数?然后我可以独立计算并打印MCC结果。我不知道Keras隐含地做了什么。
感谢您的帮助。
编辑:这里是一个记录损失历史记录的示例。如果我打印(history.matthews_correlation),我会得到与进度报告给我的相同MCC的列表。
None
for gradient. Please make sure that all of your ops have a gradient defined (i.e. are differentiable). Common ops without gradient: K.argmax, K.round, K.eval.''' - tag