-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinding-trending-coef.py
70 lines (60 loc) · 1.37 KB
/
finding-trending-coef.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
import pandas, numpy
from sklearn import linear_model
import matplotlib.pyplot as plt
# California
# - Violent crime trending slightly down
# - Popuplation growing pretty fast
"""
Here is one way to get an increasing/decreasing trend:
>>> x = [12, 34, 29, 38, 34, 51, 29, 34, 47, 34, 55, 94, 68, 81]
>>> trend = [b - a for a, b in zip(x[::1], x[1::1])]
>>> trend
[22, -5, 9, -4, 17, -22, 5, 13, -13, 21, 39, -26, 13]
"""
ys = [
31589000,
31878000,
32268000,
32667000,
33145121,
33871648,
34600463,
35001986,
35462712,
35842038,
36154147,
36457549,
36553215,
36756666,
36961664,
37338198,
37683933,
37999878,
38431393,
38792291,
38993940,
39296476,
39536653,
]
xs = numpy.array(range(0, len(ys))).reshape(-1, 1)
clf = linear_model.LinearRegression()
clf.fit(xs, ys)
# print(clf.score([[2018]], [636646]))
predictions_y = clf.predict(xs)
plt.plot(xs, predictions_y, color='blue', linewidth=3)
plt.scatter(xs, ys, color='black')
# print(len(xs))
# print(len(ys))
# print(xs)
print(ys)
print(clf.coef_)
plt.show()
# for year in range(2018, 2100):
# prediction = clf.predict([[year]])
# xs = numpy.append(xs, year)
# ys.append(prediction)
# print(year, prediction)
# print(len(ys), len(xs))
# clf.fit(numpy.array(xs).reshape(-1,1), ys)
# plt.scatter(xs, ys, color='black')
# plt.show()