예제 #1
0
def cluster_nn(X_train, y_train, X_test, y_test, savedir, ds, cluster_type):
    logging.info(
        'Running neural net with {} clusters as features'.format(cluster_type))
    pipe = A3.baseline_ann(X_train, y_train, ds)
    ypred = pipe.predict(X_test)
    util.confusionMatrix('{}-{}-ann'.format(ds, cluster_type), y_test, ypred,
                         savedir)
    return f1_score(y_test, ypred)
예제 #2
0
def dr_ann(X_train,
           y_train,
           X_test,
           y_test,
           dr_steps,
           savedir,
           ds,
           cluster=None):
    if cluster is not None:
        c = ' with clustering from {}'.format(cluster)
    else:
        c = ''
    logging.info('ANN: Running baseline neural net' + c)
    baseline = A3.baseline_ann(X_train, y_train, ds)
    ypred = baseline.predict(X_test)
    util.confusionMatrix('{}{}-baseline'.format(ds, cluster), y_test, ypred,
                         savedir)

    scores = [f1_score(y_test, ypred)]
    score_names = ['baseline']
    for dr_step in dr_steps:
        drname = dr_step.__class__.__name__.lower()
        score_names.append(drname)
        logging.info('ANN: Running neural net with {} dimension reduction'.
                     format(drname) + c)
        # Get trained ann with dr
        ann = A3.dr_ann(X_train, y_train, dr_step, ds)
        ypred = ann.predict(X_test)
        util.confusionMatrix('{}-{}{}'.format(ds, drname, cluster), y_test,
                             ypred, savedir)
        scores.append(f1_score(y_test, ypred))

    logging.info('ANN {} F1 Scores: {}'.format(c, scores))
    util.plotBarScores(scores,
                       score_names,
                       ds,
                       savedir,
                       phaseName='{}-{}'.format(ds, cluster))
    plt.close('all')