-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinearRegression_learning_execute2.py
More file actions
50 lines (36 loc) · 1.17 KB
/
Copy pathLinearRegression_learning_execute2.py
File metadata and controls
50 lines (36 loc) · 1.17 KB
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
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
font_path = '/usr/share/fonts/truetype/takao-gothic/TakaoPGothic.ttf'
font_prop = FontProperties(fname=font_path)
matplotlib.rcParams['font.family'] = font_prop.get_name()
# モデルをインポート
from LinearRegression import LinearRegression
X = np.random.randn(100,1)
t = np.random.randint(-100,100 ,size=(100,1)) * X
model = LinearRegression()
cost = []
for i in range(1000):
#仮説の計算
y = model.predict(X)
#目的関数(コスト関数)の値を記録
J = model.cost_function(y,t)
cost.append(J)
#パラメータの更新(学習)
model.gradient_descent(X,y,t)
# plt.plot(cost)
# plt.show()
#===========================================
# 実施
peoples = 1
price = model.predict(peoples)
print("人口が+100人の時、予測される税収の増減は %d"% price, "百万円")
#===========================================
plt.xlim([-3,3])
plt.ylim([-300,300])
plt.scatter(X, t)
plt.scatter(X, y, color='orange')
plt.xlabel('街の人口の増減 [百人]')
plt.ylabel('税収の増減 [百万円]')
plt.show()