コード例 #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
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)
        mse = ascdata.multi_MSE(kf_y_test, kf_y_test_pred)
        mses.append(mse)
        print "mse:", mse
        r2 = ascdata.multi_r2(kf_y_test, kf_y_test_pred)
        r2s.append(r2)
        print "r2:", r2
    overall_mse = np.mean(mses)
    overall_rmse = sqrt(overall_mse)
    overall_r2 = np.mean(r2s)
    print "KFold cross validation MSE:", overall_mse
    print "KFold cross validation RMSE:", overall_rmse
    print "KFold cross validation r2:", overall_r2