예제 #1
0
def scale(data_matrix):
    num_rows, num_cols = shape(data_matrix)
    means = [mean(get_column(data_matrix,j))
             for j in range(num_cols)]
    stdevs = [standard_deviation(get_column(data_matrix,j))
              for j in range(num_cols)]
    return means, stdevs
예제 #2
0
파일: 1A.py 프로젝트: etscrivner/dse
def main():
    """The application entry point"""
    print 'EXERCISE 1A'
    print '==========='
    print 'This program takes a CSV file, asks you to select a row from that'
    print 'file, and then computes the mean and standard deviation of the'
    print 'values in that row.'
    print
    file_path = io.get_and_confirm_input('Enter csv file with values: ')
    data = io.read_csv_file(file_path)

    if not data:
        raise RuntimeError('No data found in file {}'.format(file_path))

    column = io.choose_from_list(
        'Which column would you like to use:', data[0].keys())

    if column not in data[0]:
        raise RuntimeError('Invalid column {}'.format(column))

    values = linked_list.LinkedList()
    for each in data:
        values.insert(each[column])

    for each in values:
        print each

    print 'Mean: ', statistics.mean(values)
    print 'Std Dev: ', statistics.standard_deviation(values)
def scale(data_matrix):
    """вернуть средние и стандартные отклонения для каждого столбца"""
    num_rows, num_cols = shape(data_matrix)
    means = [mean(get_column(data_matrix,j))
             for j in range(num_cols)]
    stdevs = [standard_deviation(get_column(data_matrix,j))
              for j in range(num_cols)]
    return means, stdevs
예제 #4
0
    def normalized_data(self, data):
        """Return the given data in normalized form.

        Arguments:
            data(list): A list of data points

        Returns:
            list: Same data points, normalized.
        """
        mean = statistics.mean(data)
        stddev = statistics.standard_deviation(data)
        return [(each - mean)/stddev for each in data]
예제 #5
0
                    [random.random() for _ in range(50)] +
                    [200 + random.random() for _ in range(50)])

    print("bootstrap_statistic(close_to_100, median, 100):")
    print(bootstrap_statistic(close_to_100, median, 100))
    print("bootstrap_statistic(far_from_100, median, 100):")
    print(bootstrap_statistic(far_from_100, median, 100))
    print()

    random.seed(0)  # so that you get the same results as me

    bootstrap_betas = bootstrap_statistic(list(zip(x, daily_minutes_good)),
                                          estimate_sample_beta, 100)

    bootstrap_standard_errors = [
        standard_deviation([beta[i] for beta in bootstrap_betas])
        for i in range(4)
    ]

    print("bootstrap standard errors", bootstrap_standard_errors)
    print()

    print("p_value(30.63, 1.174)", p_value(30.63, 1.174))
    print("p_value(0.972, 0.079)", p_value(0.972, 0.079))
    print("p_value(-1.868, 0.131)", p_value(-1.868, 0.131))
    print("p_value(0.911, 0.990)", p_value(0.911, 0.990))
    print()

    print("regularization")

    random.seed(0)
def least_squares_fit(x, y):
    """при заданных обучающих значениях x и y,
    найти значения alpha и beta на основе МНК"""
    beta = correlation(x, y) * standard_deviation(y) / standard_deviation(x)
    alpha = mean(y) - beta * mean(x)
    return alpha, beta
def least_squares_fit(x, y):
    """given training values for x and y,
    find the least-squares values of alpha and beta"""
    beta = correlation(x, y) * standard_deviation(y) / standard_deviation(x)
    alpha = mean(y) - beta * mean(x)
    return alpha, beta
예제 #8
0
 def test_should_correctly_compute_standard_deviation(self):
     self.assertAlmostEqual(
         2.73861,
         statistics.standard_deviation(range(1, 10)),
         places=5)