回答編集履歴
1
追記
test
CHANGED
@@ -1 +1,63 @@
|
|
1
1
|
``model = LinearRegression()``の後に``model.fit(X, Y)``が必要です。
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
---
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
【ご参考】
|
10
|
+
|
11
|
+
```Python
|
12
|
+
|
13
|
+
import pandas as pd
|
14
|
+
|
15
|
+
import numpy as np
|
16
|
+
|
17
|
+
import matplotlib.pyplot as plt
|
18
|
+
|
19
|
+
from sklearn.linear_model import LinearRegression
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
icecream = [[1,464],[2,397],[3,493],[4,617],[5,890],[6,883],[7,1292],[8,1387],[9,843],[10,621],[11,459],[12,561]]
|
24
|
+
|
25
|
+
tempreture = [[1,10.6],[2,12,2],[3,14.9],[4,20.3],[5,25.2],[6,26.3],[7,29.7],[8,31.6],[9,27.7],[10,22.6],[11,15.5],[12,13.8]]
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
X = pd.DataFrame([u[1] for u in tempreture])
|
30
|
+
|
31
|
+
Y = pd.DataFrame([u[1] for u in icecream])
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
model = LinearRegression()
|
36
|
+
|
37
|
+
model.fit(X, Y)
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
plt.scatter(X, Y)
|
42
|
+
|
43
|
+
plt.plot(X, model.predict(X),"red")
|
44
|
+
|
45
|
+
plt.grid()
|
46
|
+
|
47
|
+
plt.show()
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
![イメージ説明](a8c16442085b1152572f23ebfa71d3c6.png)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
pandas 1.0.5
|
56
|
+
|
57
|
+
numpy 1.18.5
|
58
|
+
|
59
|
+
matplotlib 3.2.2
|
60
|
+
|
61
|
+
scikit-learn 0.23.1
|
62
|
+
|
63
|
+
Python 3.8.3
|