示例#1
0
    def on_epoch_end(self, epoch, logs={}):
        y_pred_tr = self.model.predict_proba(self.X_tr)
        logs['gini_tr'] = gini.gini_sklearn(self.y_tr, y_pred_tr)
        y_pred_val = self.model.predict_proba(self.X_val)
        logs['gini_val'] = gini.gini_sklearn(self.y_val, y_pred_val)

        # if logs['gini_val'] > self.best_lap:
        #     self.best_lap = logs['gini_val']

        #     global pred_val, pred_test
        #     pred_val = y_pred_val
        #     pred_test = self.model.predict_proba(X_test)

        print('Gini Score in training set: {},  test set: {}'.format(
            logs['gini_tr'], logs['gini_val']))
        return
示例#2
0
    def on_epoch_end(self, epoch, logs={}):
        y_pred_tr = self.model.predict_proba(self.X_tr)
        #         roc = roc_auc_score(self.y_tr, y_pred_tr)
        #         logs['roc_auc'] = roc
        #         logs['gini_tr'] = (roc * 2 ) - 1
        logs['gini_tr'] = gini.gini_sklearn(self.y_tr, y_pred_tr)

        y_pred_val = self.model.predict_proba(self.X_val)
        #         roc = roc_auc_score(self.y_val, y_pred_val)
        #         logs['roc_auc_val'] = roc
        #         logs['gini_val'] = (roc * 2 ) - 1
        logs['gini_val'] = gini.gini_sklearn(self.y_val, y_pred_val)

        print('Gini Score in training set: {},  test set: {}'.format(
            logs['gini_tr'], logs['gini_val']))
        return
示例#3
0
                      epochs=epochs,
                      verbose=99,
                      callbacks=callbacks)

            # delete current model
            del model

            # load best model of each run
            model = create_model()
            model.load_weights(checkpoint_path, by_name=False)

            # For train and valid only
            pred_val = model.predict_proba(X_val).reshape(-1, )

            # Store average score for evaluate model
            score_fold.append(gini.gini_sklearn(y_val, pred_val))

            oof_train[val_index] += pred_val / runs_per_fold

            print('Run {}: {} \n'.format(j + 1, score_fold[j]))

            pred_test_lap = model.predict_proba(X_test).reshape(-1, )
            pred_test += pred_test_lap / runs_per_fold

        # Store test predictions for submissions

        oof_test += pred_test / KFOLDS

        scores.append(gini.gini_sklearn(y_val, oof_train[val_index]))
        print('[Fold {}/{} Gini score: {} \n]'.format(i + 1, KFOLDS,
                                                      scores[i]))
示例#4
0
                  verbose=99,
                  callbacks=callbacks)

        # delete current model
        del model

        # load best model of each run
        model = create_model()
        model.load_weights(checkpoint_path, by_name=False)

        # For train and valid only
        pred_val = model.predict_proba(X_val)
        oof_train[val_index] += pred_val / runs_per_fold

        # Store average score for evaluate model
        score_fold.append(gini.gini_sklearn(y_val, pred_val))

        print('Run {}: {}'.format(j + 1, score_fold[j]))

        pred_test_lap = model.predict_proba(X_test)
        pred_test += pred_test_lap / runs_per_fold

    # Store test predictions for submissions

    oof_test += pred_test / KFOLDS

    scores.append(np.mean(score_fold))
    print('[Fold {}/{} Gini score: {}]'.format(i + 1, KFOLDS, scores[i]))

    gc.collect()
    print('[Fold {}/{} END]'.format(i + 1, KFOLDS))
示例#5
0
                            epochs=epochs,
                            verbose=99,
                            callbacks=callbacks)

    model.fit(X_tr, y_tr, shuffle=False)

    # We want the best model from checkpoint
    del model
    model = load_model(checkpoint_path)

    # For train and valid only
    pred_val = model.predict_proba(X_val)
    oof_train[val_index] = pred_val

    # Store average score for evaluate model
    scores.append(gini.gini_sklearn(y_val, pred_val))

    # Store test predictions for submissions
    pred_test = model.predict_proba(X_test) / KFOLDS
    oof_test += pred_test

    print('[Fold {}/{} Gini score: {}]'.format(i + 1, KFOLDS, scores[i]))

    gc.collect()
    print('[Fold {}/{} END]'.format(i + 1, KFOLDS))

print('Average score: {}'.format(np.mean(scores)))
print('Total run time: {} seconds'.format(time.time() - tmp))

# Export oof_train
file_path = os.path.join(OOF_PATH, MODEL_NAME + '_train.csv')