Ejemplo n.º 1
0
def main():
    global nn_input_dim, nn_output_dim, gamma

    iters = 15000
    hl_nodes = 10
    gamma_trials = [0.01, 0.1, 0, 1, 10, 100]

    X_train, y_train, X_test, y_test = get_data()

    for gamma in gamma_trials:

        print "\n-------For gamma = %f and number of hidden layers = %d----------\n" % (
            gamma, hl_nodes)

        model = train_model(X_train, y_train, hl_nodes, 4, iters, False)

        t = predict(X_train, model)
        f1 = class_stats(t, y_train, 4)
        acc_train.append(f1)

        y_pred = predict(X_test, model)
        f1 = class_stats(y_pred, y_test, 4)
        acc_test.append(f1)

    plot_points(gamma_trials, acc_train, 'gamma', 'accuray')
    plot_points(gamma_trials, acc_test, 'gamma', 'accuracy')
Ejemplo n.º 2
0
def perform_multinomial_nb_dir(params):
    acc_val = []
    for s in [1, 3, 5, 7, 9]:
        train_set, train_label, test_set, test_label = create_datasets(s)
        y_pred, y_score = predict_multinomial_nb_dir(train_set, train_label,
                                                     test_set, params)
        plot_pr_curve(test_label, y_score)
        acc, _ = class_stats(y_pred, test_label, 2)
        acc_val.append(acc)
    print sum(acc_val) / 5
Ejemplo n.º 3
0
y_train = load_data_csv("DS3/train_labels.csv")
X_train_proj = lda_projected_X(X_train, y_train, 1)

# Loading test data and projecting into derived space
X_test = load_data_csv("DS3/test.csv")
y_test = load_data_csv("DS3/test_labels.csv")
X_test_proj = lda_projected_X(X_test, y_test, 1)

# Re-encoding output
y_train[y_train == 1] = 0
y_train[y_train == 2] = 1
y_test[y_test == 1] = 0
y_test[y_test == 2] = 1

# Fitting model
lr = linear_model.LinearRegression()
lr.fit(X_train_proj, y_train)

# Prediction
y_pred_actual = lr.predict(X_test_proj)
y_pred = y_pred_actual.copy()

# Thresholding
y_pred[y_pred < 0.5] = 0
y_pred[y_pred >= 0.5] = 1

# Plotting and printing out results
plot_3d(X_test, y_test)
class_stats(y_pred, y_test, 2)
plot_2d_model(X_test_proj, y_test, lr.coef_[0], lr.intercept_)
Ejemplo n.º 4
0
def print_performance_metrics(model, X_test, y_test):
    print "\n----Model performance metrics------\n"

    y_pred = model.predict(X_test)
    class_stats(y_pred, y_test, 4)
Ejemplo n.º 5
0
def perform_multinomial_nb():
    train_set, train_label, test_set, test_label = create_datasets(1)
    y_pred, y_score = predict_multinomial_nb(train_set, train_label, test_set)
    plot_pr_curve(test_label, y_score)
    class_stats(y_pred, test_label, 2)