def scale(data_matrix):
    """ returns the means and stds of each column in data_matrix """
    num_rows, num_cols = shape(data_matrix)

    means = [mean(get_col(data_matrix, col)) for col in range(num_cols)]
    stds = [standard_deviation(get_col(data_matrix, col)) for col in range(num_cols)]
    return means, stds
Example #2
0
def scale(data_matrix):
    """ returns the means and stds of each column in data_matrix """
    num_rows, num_cols = shape(data_matrix)

    means = [mean(get_col(data_matrix, col)) for col in range(num_cols)]
    stds = [
        standard_deviation(get_col(data_matrix, col))
        for col in range(num_cols)
    ]
    return means, stds
Example #3
0
def least_squares_fit(x, y):
    """ given training values for x,y computes the least squares values for
        beta_0 and beta_1"""
    beta_1 = covariance(x,y)/variance(x)
    beta_0 = mean(y) - beta_1 * mean(x)
    return beta_0, beta_1