예제 #1
0
def train_lr():
    train_x, train_y = regression.load_data_set('abalone.txt')
    # calculate the training y using the data set of the 0-100 samples
    y_train_hat1 = regression.local_weight_array_test(train_x[0:99], train_x[0:99], train_y[0:99], k=0.1)
    y_train_hat2 = regression.local_weight_array_test(train_x[0:99], train_x[0:99], train_y[0:99], k=1)
    y_train_hat3 = regression.local_weight_array_test(train_x[0:99], train_x[0:99], train_y[0:99], k=10)

    # calculate the training error and print
    y_train_error1 = res_error(train_y[0:99], y_train_hat1.T)
    y_train_error2 = res_error(train_y[0:99], y_train_hat2.T)
    y_train_error3 = res_error(train_y[0:99], y_train_hat3.T)
    print 'k = 0.1, training error is: ', y_train_error1
    print 'k = 1,   training error is: ', y_train_error2
    print 'k = 10,  training error is: ', y_train_error3

    print '=' * 50
    # calculate the test y using the data set of the 100-199 samples
    y_test_hat1 = regression.local_weight_array_test(train_x[100:199], train_x[0:99], train_y[0:99], k=0.1)
    y_test_hat2 = regression.local_weight_array_test(train_x[100:199], train_x[0:99], train_y[0:99], k=1)
    y_test_hat3 = regression.local_weight_array_test(train_x[100:199], train_x[0:99], train_y[0:99], k=10)

    # calculate the test error and print
    y_test_error1 = res_error(train_y[100:199], y_test_hat1.T)
    y_test_error2 = res_error(train_y[100:199], y_test_hat2.T)
    y_test_error3 = res_error(train_y[100:199], y_test_hat3.T)
    print 'k = 0.1, test error is: ', y_test_error1
    print 'k = 1,   test error is: ', y_test_error2
    print 'k = 10,  test error is: ', y_test_error3
def ridge_test():
    import matplotlib.pyplot as plt
    x_mat, y_mat = regression.load_data_set('abalone.txt')
    ridge_weights = ridge_train(x_mat, y_mat)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(ridge_weights)
    plt.show()
예제 #3
0
def ridge_test():
    import matplotlib.pyplot as plt
    x_mat, y_mat = regression.load_data_set('abalone.txt')
    ridge_weights = ridge_train(x_mat, y_mat)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(ridge_weights)
    plt.show()
def test_plot_weight():
    x_arr, y_arr = regression.load_data_set('ex0.txt')
    regression.plot_local_weight([1.0, 0.5], x_arr, k=0.1)
def test_basic():
    x_arr, y_arr = regression.load_data_set('ex0.txt')
    w = regression.calc_weight(x_arr, y_arr)
    print w
def test_stage():
    x_arr, y_arr = regression.load_data_set('abalone.txt')
    stage_wise(x_arr, y_arr, 0.01, 200)
def test_plot_weight():
    x_arr, y_arr = regression.load_data_set('ex0.txt')
    regression.plot_local_weight([1.0, 0.5], x_arr, k=0.1)
def test_basic():
    x_arr, y_arr = regression.load_data_set('ex0.txt')
    w = regression.calc_weight(x_arr, y_arr)
    print w