コード例 #1
0
def plot_predictions(prog_num, bp, inX, iny):
    plt.cla()
    X_bp, y_bp = ascdata.get_bp_data(prog_num, bp, inX, iny)
    iny_pred = clf.predict(X_bp)
    plot_inputs = range(1,11)
    plt.plot(plot_inputs, y_bp.flatten(), 'bx')
    plt.plot(plot_inputs, iny_pred.flatten(),'ro')
    plt.savefig("multitask_" + str(prog_num) + "_" + str(bp) + ".png")
    bp_rms = ascdata.multi_RMSE(y_bp, iny_pred)
    bp_r2 = ascdata.multi_r2(y_bp, iny_pred)
    print "rms total for prognum", prog_num, "at breakpoint", bp, bp_rms
    print "r2 total for prognum", prog_num, "at breakpoint", bp, bp_r2
コード例 #2
0
from math import sqrt

### IMPORT DATA ###
print "IMPORTING DATA"
X_raw, y_raw = ascdata.load_asc_data()
X_nonzero,y_nonzero = ascdata.remove_zeros(X_raw, y_raw)
X,y = ascdata.remove_crazy(X_nonzero,y_nonzero, 100)
X_train, y_train, X_test, y_test = ascdata.split_train_test(X, y)

### GET PREDICTIONS ###
print "GETTING PREDICTIONS"
clf = neural_network.MLPRegressor()
clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)

rms_test = ascdata.multi_RMSE(y_test, y_pred)
print "overall rms test", rms_test

score = clf.score(X_test, y_test)
print "overall score", score

# Get cross validation RMS and r^2
def get_kfold_scores(inX, iny, k):
    N = inX.shape[0]
    kf = KFold(N, k, shuffle=True)
    mses=[]
    r2s = []
    for train_index, test_index in kf:
        kf_X_train, kf_X_test = inX[train_index], inX[test_index]
        kf_y_train, kf_y_test = iny[train_index], iny[test_index]
        kf_y_test_pred = clf.predict(kf_X_test)