예제 #1
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
예제 #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
예제 #3
0
def norm_matrix(data_matrix):
    """ rescales the input columns to have zero mean and stdev 1. Ignores
        cols with no deviation """
    means, stds = scale(data_matrix)

    def norm(i, j):
        if stds[j] > 0:
            return (data_matrix[i][j] - means[j]) / stds[j]
        else:
            return data_matrix[i][j]

    num_rows, num_cols = shape(data_matrix)
    return make_matrix(num_rows, num_cols, norm)
예제 #4
0
def norm_matrix(data_matrix):
    """ rescales the input columns to have zero mean and stdev 1. Ignores
        cols with no deviation """
    means, stds = scale(data_matrix)

    def norm(i, j):
        if stds[j] > 0:
            return (data_matrix[i][j] - means[j]) / stds[j]
        else:
            return data_matrix[i][j]

    num_rows, num_cols = shape(data_matrix)
    return make_matrix(num_rows, num_cols, norm)