Exemple #1
0
    def execute(self):
        parser = argparse.ArgumentParser()
        parser.add_argument(
            'CSVFILE', help='path to csv file with historical data.')
        parser.add_argument(
            'ESTVAL', help='an estimated value')
        args = parser.parse_args()
        file_path = args.CSVFILE
        estimated_value = float(args.ESTVAL)
        csv_data = io.read_csv_file(file_path)

        if not csv_data:
            print 'ERROR: No data'
            sys.exit(1)

        columns = csv_data[0].keys()
        x_column = io.choose_from_list('X Column:', columns)
        y_column = io.choose_from_list('Y Column:', columns)
        x_data = [float(each[x_column]) for each in csv_data if each[x_column]]
        y_data = [float(each[y_column]) for each in csv_data if each[y_column]]
        print

        x_data, y_data = probe.trim_to_equal_length(x_data, y_data)
        print 'X DATA: {}'.format(x_data)
        print 'Y DATA: {}'.format(y_data)
        print

        beta_0 = statistics.beta_0(x_data, y_data)
        print u'\u03B20: {}'.format(beta_0)

        beta_1 = statistics.beta_1(x_data, y_data)
        print u'\u03B21: {}'.format(beta_1)

        integ = integration.Integrator(20, 0.000001)
        tdist = statistics.make_t_distribution(len(x_data) - 2)
        itdist = lambda x: integ.integrate_minus_infinity_to(tdist, x)

        std_dev = (
            statistics.standard_deviation_around_regression(x_data, y_data)
        )
        print "StdDev: ", std_dev

        projection = beta_0 + beta_1 * estimated_value
        print 'Projection: ', projection

        print 't(70 percent): ', integration.approximate_inverse(itdist, 0.85)
        print 't(90 percent): ', integration.approximate_inverse(itdist, 0.95)

        range70 = statistics.prediction_range(
            estimated_value, 0.85, x_data, y_data
        )
        range90 = statistics.prediction_range(
            estimated_value, 0.95, x_data, y_data
        )
        print 'Range(70 percent) =', projection + range70, \
            'UPI =', projection - range70, 'LPI =', range70
        print 'Range(90 percent) =', projection + range90, \
            'UPI =', projection - range90, 'LPI =', range90
Exemple #2
0
    def get_regression(self):
        """Returns the linear regression for this estimation method.

        Returns:
            LinearRegression: A linear regression
        """
        return statistics.LinearRegression(
            statistics.beta_0(self.x_values, self.y_values), statistics.beta_1(self.x_values, self.y_values)
        )
Exemple #3
0
    def execute(self):
        parser = argparse.ArgumentParser()
        parser.add_argument(
            'CSVFILE', help='path to csv file with historical data.')
        args = parser.parse_args()
        file_path = args.CSVFILE
        csv_data = io.read_csv_file(file_path)

        if not csv_data:
            print 'ERROR: No data'
            sys.exit(1)

        columns = csv_data[0].keys()
        x_column = io.choose_from_list('X Column:', columns)
        y_column = io.choose_from_list('Y Column:', columns)
        x_data = [float(each[x_column]) for each in csv_data]
        y_data = [float(each[y_column]) for each in csv_data]
        #x_data, y_data = statistics.remove_outliers(x_data, y_data)
        print

        print 'X DATA: {}'.format(x_data)
        print 'Y DATA: {}'.format(y_data)
        print

        beta_0 = statistics.beta_0(x_data, y_data)        
        print u'\u03B20: {}'.format(beta_0)
        warnings = statistics.beta_0_warnings(beta_0)
        if warnings:
            print 'WARNINGS:'
            print '\n'.join(warnings)
        print

        beta_1 = statistics.beta_1(x_data, y_data)
        print u'\u03B21: {}'.format(beta_1)
        warnings = statistics.beta_1_warnings(beta_1)
        if warnings:
            print 'WARNINGS:'
            print '\n'.join(warnings)
        print