示例#1
0
    least_error = 100
    target_alpha = 1
    alphas = np.linspace(-20, -18, 10)
    for alp in alphas:
        w = do_regression(phi, y, alp)
        y_prime = (grand_order(polyx, order) * w)
        error = data_reading.MeanSquareError(y_prime, polyy)
        if error <= least_error:
            target_alpha = alp
            least_error = error
    return target_alpha


if '__main__' == __name__:
    poly_data, poly_keys = data_reading.readMatFile("poly_data.mat")
    order = 10

    X, y = grand_order(poly_data['sampx'][0], order), poly_data['sampy']
    polyx, polyy = poly_data['polyx'][0], poly_data['polyy']
    count_data, count_keys = data_reading.readMatFile("count_data.mat")
    target_alpha = choose_hyper(X, y, polyx, polyy, order)
    w = do_regression(X, y, target_alpha)
    y_prime = grand_order(polyx, order) * w

    fig = plt.figure("LASSO")
    ax = fig.add_subplot(111)
    ax.plot(poly_data['sampx'][0],
            y,
            color='r',
            linestyle='',
示例#2
0
#-*- coding:utf-8 -*-
import numpy as np
import data_reading
import matplotlib.pyplot as plt
from data_reading import grand_order
from LS import do_regression as LSregression
from RLS import do_regression as RLSregression
from RLS import choose_hyper as RLS_hyper
from LASSO import do_regression as LASSOregression
from LASSO import choose_hyper as LASSO_hyper
from RR import do_regression as RRregression
from BR import do_regression as BRregression
from BR import choose_hyper as BR_hyper

if __name__ == "__main__":
    poly_data, poly_keys = data_reading.readMatFile("poly_data.mat")
    order = 5
    sampx = poly_data['sampx'][0]
    sampy = poly_data['sampy']
    polyx = poly_data['polyx'][0]
    polyy = poly_data['polyy']

    total_length = len(sampx)
    percents = [0.1, 0.25, 0.5, 0.75]

    result = np.zeros((4, 5))
    for j in range(1000):
        MSEs = []
        for percent in percents:
            try:
                mse = []