-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegression.py
More file actions
32 lines (25 loc) · 687 Bytes
/
Regression.py
File metadata and controls
32 lines (25 loc) · 687 Bytes
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
from statistics import mean
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use('fivethirtyeight')
xs=np.array([1,2,3,4,5,6],dtype=np.float64)
ys=np.array([5,4,6,5,6,7],dtype=np.float64)
def best_fit_slope_and_intercept(xs,ys):
m=(((mean(xs)*mean(ys)) -mean(xs*ys)) /
((mean(xs)*mean(xs))-mean(xs*xs)))
b=mean(ys)-m*mean(xs)
return m,b
m,b=best_fit_slope_and_intercept(xs,ys)
regression_line=[(m*x)+b for x in xs]
predict_x=8
predict_y=(m*predict_x)+b
plt.scatter(xs,ys)
plt.scatter(predict_x,predict_y,color='g')
plt.plot(xs,regression_line)
plt.show()
#for x in xs:
# regression
print(m,b)
plt.plot(xs,ys)
plt.show()