質問編集履歴
1
完成したコードを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,4 +44,36 @@
|
|
44
44
|
1578 __bool__ = __nonzero__
|
45
45
|
|
46
46
|
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
|
47
|
-
```
|
47
|
+
```
|
48
|
+
|
49
|
+
# できましたー(≧▽≦)
|
50
|
+
[can110](https://teratail.com/users/can110) 様、ありがとうございます(≧▽≦) できましたー!
|
51
|
+
|
52
|
+
> `px = np.arange(X.min()[0], X.max()[0], 0.01)[:,np.newaxis]`
|
53
|
+
「最小/大値の0番目の要素」で指定するのですね(゚д゚)!
|
54
|
+
|
55
|
+
> この本は改訂版が出ているようなので、それを買いなおすか
|
56
|
+
持っているのはその改定2版なんですよ。。。orz 2018年5月11日発行のものですf^^;
|
57
|
+

|
58
|
+

|
59
|
+
|
60
|
+
**完成コード**
|
61
|
+
```python
|
62
|
+
# リスト17 単回帰分析
|
63
|
+
LinerRegr = linear_model.LinearRegression()
|
64
|
+
X = setosa[["SepalLength"]]
|
65
|
+
Y = setosa[["SepalWidth"]]
|
66
|
+
LinerRegr.fit(X, Y)
|
67
|
+
plt.scatter(X, Y, color="black")
|
68
|
+
px = np.arange(X.min()[0], X.max()[0], 0.01)[:,np.newaxis]
|
69
|
+
|
70
|
+
py = LinerRegr.predict(px)
|
71
|
+
plt.plot(px, py, color = "blue", linewidth=3)
|
72
|
+
plt.xlabel("SepalLength")
|
73
|
+
plt.ylabel("SepalWidth")
|
74
|
+
plt.show()
|
75
|
+
|
76
|
+
print(LinerRegr.coef_)# 回帰係数
|
77
|
+
print(LinerRegr.intercept_) # 切片
|
78
|
+
```
|
79
|
+

|