teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

完成したコードを追記

2018/11/07 12:14

投稿

Yukiya025
Yukiya025

スコア86

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
+ ![DScover](c2b9b78f01286209f0c113f02162d52f.jpeg)
58
+ ![Okuduke](15bf80fbdd22cd5cb43abe560e1b46ef.jpeg)
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
+ ![Result](b7db0d15b9f9e8a754a7acb9db868065.png)