Exemplo n.º 1
0
def run(
        input_data_file):
    """
    """
    # parameter values
    intercept = 0.
    slope = 0.
    param_values = {"intercept": intercept,
            "slope": slope}
    # hypothesis object
    hypo = SimpleLinearRegression()
    hypo.initialize_parameters(param_values)

    # name of file where data is stored
    #file_name = 'data/input/ex1data1.txt'
    # read in data
    data = get_input_data(input_data_file)
    # extract features
    features = data[:, 0]
    # reshape to dimension nobs x 1
    features = features.reshape((len(features), 1))
    # extract yvalues
    yvalues = data[:, 1]
    # reshape to dimension nobs x 1
    yvalues = yvalues.reshape((len(yvalues), 1))

    # cost function object
    sel = SquaredErrorLoss(hypo, features, yvalues)
    gd = GradientDescent(.0001, param_values, .000000001, sel)
    gd.algorithm()
    print gd.get_parameters()