質問編集履歴
1
完成したコードを追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -91,3 +91,67 @@
|
|
91
91
|
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
|
92
92
|
|
93
93
|
```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
# できましたー(≧▽≦)
|
98
|
+
|
99
|
+
[can110](https://teratail.com/users/can110) 様、ありがとうございます(≧▽≦) できましたー!
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
> `px = np.arange(X.min()[0], X.max()[0], 0.01)[:,np.newaxis]`
|
104
|
+
|
105
|
+
「最小/大値の0番目の要素」で指定するのですね(゚д゚)!
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
> この本は改訂版が出ているようなので、それを買いなおすか
|
110
|
+
|
111
|
+
持っているのはその改定2版なんですよ。。。orz 2018年5月11日発行のものですf^^;
|
112
|
+
|
113
|
+
![DScover](c2b9b78f01286209f0c113f02162d52f.jpeg)
|
114
|
+
|
115
|
+
![Okuduke](15bf80fbdd22cd5cb43abe560e1b46ef.jpeg)
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
**完成コード**
|
120
|
+
|
121
|
+
```python
|
122
|
+
|
123
|
+
# リスト17 単回帰分析
|
124
|
+
|
125
|
+
LinerRegr = linear_model.LinearRegression()
|
126
|
+
|
127
|
+
X = setosa[["SepalLength"]]
|
128
|
+
|
129
|
+
Y = setosa[["SepalWidth"]]
|
130
|
+
|
131
|
+
LinerRegr.fit(X, Y)
|
132
|
+
|
133
|
+
plt.scatter(X, Y, color="black")
|
134
|
+
|
135
|
+
px = np.arange(X.min()[0], X.max()[0], 0.01)[:,np.newaxis]
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
py = LinerRegr.predict(px)
|
140
|
+
|
141
|
+
plt.plot(px, py, color = "blue", linewidth=3)
|
142
|
+
|
143
|
+
plt.xlabel("SepalLength")
|
144
|
+
|
145
|
+
plt.ylabel("SepalWidth")
|
146
|
+
|
147
|
+
plt.show()
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
print(LinerRegr.coef_)# 回帰係数
|
152
|
+
|
153
|
+
print(LinerRegr.intercept_) # 切片
|
154
|
+
|
155
|
+
```
|
156
|
+
|
157
|
+
![Result](b7db0d15b9f9e8a754a7acb9db868065.png)
|