回答編集履歴
1
追記
answer
CHANGED
@@ -1,1 +1,32 @@
|
|
1
|
-
``model = LinearRegression()``の後に``model.fit(X, Y)``が必要です。
|
1
|
+
``model = LinearRegression()``の後に``model.fit(X, Y)``が必要です。
|
2
|
+
|
3
|
+
---
|
4
|
+
|
5
|
+
【ご参考】
|
6
|
+
```Python
|
7
|
+
import pandas as pd
|
8
|
+
import numpy as np
|
9
|
+
import matplotlib.pyplot as plt
|
10
|
+
from sklearn.linear_model import LinearRegression
|
11
|
+
|
12
|
+
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]]
|
13
|
+
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]]
|
14
|
+
|
15
|
+
X = pd.DataFrame([u[1] for u in tempreture])
|
16
|
+
Y = pd.DataFrame([u[1] for u in icecream])
|
17
|
+
|
18
|
+
model = LinearRegression()
|
19
|
+
model.fit(X, Y)
|
20
|
+
|
21
|
+
plt.scatter(X, Y)
|
22
|
+
plt.plot(X, model.predict(X),"red")
|
23
|
+
plt.grid()
|
24
|
+
plt.show()
|
25
|
+
```
|
26
|
+

|
27
|
+
|
28
|
+
pandas 1.0.5
|
29
|
+
numpy 1.18.5
|
30
|
+
matplotlib 3.2.2
|
31
|
+
scikit-learn 0.23.1
|
32
|
+
Python 3.8.3
|