model.load_weights(checkpoint_path)

    summary_path = os.path.join(SUMMARY_PATH, 'model_{}'.format(num_folds))
    mkdirp(summary_path)

    callbacks = [EarlyStopping(monitor='val_loss', patience=1, verbose=0, mode='auto'),
                 ModelCheckpoint(checkpoint_path, monitor='val_loss', verbose=0, save_best_only=True, mode='auto'),
                 TensorBoard(log_dir=summary_path, histogram_freq=0)]
    model.fit(X_train, y_train, batch_size=BATCH_SIZE, nb_epoch=NB_EPOCHS,
              shuffle=True,
              verbose=1,
              validation_data=(X_valid, y_valid),
              callbacks=callbacks)

    predictions_valid = model.predict(X_valid, batch_size=100, verbose=1)
    score_valid = log_loss(y_valid, predictions_valid)
    scores_total.append(score_valid)

    print('Score: {}'.format(score_valid))

    predictions_test = model.predict(X_test, batch_size=100, verbose=1)
    predictions_total.append(predictions_test)

    num_folds += 1

score_geom = calc_geom(scores_total, MAX_FOLDS)
predictions_geom = calc_geom_arr(predictions_total, MAX_FOLDS)

submission_path = os.path.join(SUMMARY_PATH, 'submission_{}_{:.2}.csv'.format(int(time.time()), score_geom))
write_submission(predictions_geom, X_test_ids, submission_path)
Example #2
0
                wait += 1
                print(
                    'Validation loss did not improve for {}/{} epochs.'.format(
                        wait, patience))

            if wait == 2:
                print(
                    'Stopping early. Validation loss did not improve for {}/{} epochs.'
                    .format(wait, patience))
                break

        model.summary_writer.close()
        scores_total.append(score)

        print('Begin evaluation...')
        predictions = model.evaluate(X_test)
        predictions_total.append(predictions)

    num_folds += 1

score_geom = calc_geom(scores_total, num_folds)
predictions_geom = calc_geom_arr(predictions_total, num_folds)

print('Writing submission for {} folds, score: {}...'.format(
    num_folds, score_geom))
submission_dest = os.path.join(
    SUMMARY_PATH, 'submission_{}_{}.csv'.format(int(time.time()), score_geom))
write_submission(predictions_geom, X_test_ids, submission_dest)

print('Done.')
Example #3
0
            if loss < best:
                print('New best validation loss! Was: {}, Now: {}'.format(best, loss))
                best = loss
                wait = 0
            else:
                wait += 1
                print('Validation loss did not improve for {}/{} epochs.'.format(wait, patience))

            if wait == 2:
                print('Stopping early. Validation loss did not improve for {}/{} epochs.'.format(wait, patience))
                break


        model.summary_writer.close()
        scores_total.append(score)

        print('Begin evaluation...')
        predictions = model.evaluate(X_test)
        predictions_total.append(predictions)

    num_folds += 1

score_geom = calc_geom(scores_total, num_folds)
predictions_geom = calc_geom_arr(predictions_total, num_folds)

print('Writing submission for {} folds, score: {}...'.format(num_folds, score_geom))
submission_dest = os.path.join(SUMMARY_PATH, 'submission_{}_{}.csv'.format(int(time.time()), score_geom))
write_submission(predictions_geom, X_test_ids, submission_dest)

print('Done.')
Example #4
0
    mkdirp(summary_path)

    callbacks = [
        EarlyStopping(monitor='val_loss', patience=2, verbose=0, mode='auto'),
        ModelCheckpoint(checkpoint_path, monitor='val_loss', verbose=0, save_best_only=True, mode='auto'),
        TensorBoard(log_dir=summary_path, histogram_freq=0)
    ]
    model.fit(X_train, y_train, \
            batch_size=BATCH_SIZE, nb_epoch=NB_EPOCHS, \
            shuffle=True, \
            verbose=1, \
            validation_data=(X_valid, y_valid), \
            callbacks=callbacks)

    predictions_valid = model.predict(X_valid, batch_size=100, verbose=1)
    score_valid = log_loss(y_valid, predictions_valid)
    scores_total.append(score_valid)

    print('Score: {}'.format(score_valid))

    predictions_test = model.predict(X_test, batch_size=100, verbose=1)
    predictions_total.append(predictions_test)

    num_folds += 1

score_geom = calc_geom(scores_total, MAX_FOLDS)
predictions_geom = calc_geom_arr(predictions_total, MAX_FOLDS)

submission_path = os.path.join(SUMMARY_PATH, 'submission_{}_{:.2}.csv'.format(int(time.time()), score_geom))
write_submission(predictions_geom, X_test_ids, submission_path)