-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplestat.py
70 lines (53 loc) · 1.56 KB
/
simplestat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import random
from linear_regression import *
def get_linear_reg(x,y):
#prepare data
datalist = []
for i in range(len(x)):
datalist.append(datapoint([x[i],y[i]]))
data = dataset(datalist)
[a,b,pearson_r,sum_err] = linear_reg(data)
result = dict()
result['slope'] = round(b,3)
result['intercept'] = round(a,3)
result['r_value'] = round(pearson_r,3)
result['p_value'] = -1.0
result['std_err'] = round(sum_err,3)
result['avgx'] = int(get_avg(x))
result['avgy'] = int(get_avg(y))
return result
def get_avg(vals):
sumv = sum(vals)
n = float(len(vals))
return round(sumv/n,3)
def get_median(vals):
n = len(vals)
midpoint = int(round(n/2,0)) # when length is odd always choose the upper element
return round(vals[midpoint],3)
def random_data(factor,size):
""" some random data along a line """
data = list()
a = 3
b = 10
for i in range(size):
d = {'x':i+a, 'y': i+b + random.random()*factor}
data.append(d)
return data
def random_data_skew(factor):
""" some random data along a line """
data = list()
a = 3
b = 10
size = 20
for i in range(size):
d = {'x':i+a, 'y': i+b + random.random()*factor}
data.append(d)
data.append({'x':5, 'y': 22})
data.append({'x':6, 'y': 23})
data.append({'x':7, 'y': 21})
data.append({'x':8, 'y': 25})
data.append({'x':20, 'y': 17})
data.append({'x':21, 'y': 18})
data.append({'x':22, 'y': 16})
data.append({'x':23, 'y': 19})
return data