如何评估keras中的列车和验证集?

时间:2018-04-02 04:12:33

标签: keras

class RocAucEvaluation(Callback):
    def __init__(self,  validation_data=(), interval=1):
        super(Callback, self).__init__()
        self.interval = interval
        self.X_val, self.y_val = validation_data
    def on_epoch_end(self, epoch, logs={}):
        if epoch % self.interval == 0:
            y_pred = self.model.predict(self.X_val, verbose=0)
            score = roc_auc_score(self.y_val, y_pred)
            print("\n ROC-AUC - epoch: %d -  score: %.6f \n" % (epoch+1, score))

RocAuc = RocAucEvaluation(validation_data=(validate_x, validate_y), interval=1)
model.fit(train_x, train_y, batch_size=20000, epochs=3, verbose=1, callbacks=[RocAuc],class_weight={0:0.0025,1:0.9985},\
         validation_data=(validate_x, validate_y))

我的代码可以在验证集的每个时期评估AUC。如何修改代码以使其同时在列车和验证集上进行评估?

0 个答案:

没有答案