質問編集履歴

2

画像の追加

2022/10/02 00:16

投稿

wpjrnfa
wpjrnfa

スコア0

test CHANGED
File without changes
test CHANGED
@@ -19,7 +19,6 @@
19
19
  return model_lr.predict(x_test)
20
20
  pred(df.T)
21
21
  #array([138.])
22
-
23
- ```![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-10-02/77358063-4079-471c-9921-35d80a5c9308.jpeg)
22
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-10-02/d637c182-cdf9-446b-a45f-11902e525c78.jpeg)
24
23
 
25
24
  このエラーはどのようにして改善すれば良いですか?データ右下の空欄を回帰分析で求めるようにしたいです

1

コードを入力

2022/10/02 00:12

投稿

wpjrnfa
wpjrnfa

スコア0

test CHANGED
File without changes
test CHANGED
@@ -1,3 +1,25 @@
1
+ ```ここに言語を入力
2
+ list = [
3
+ [0,20, 10, 20, 20],
4
+ [0,40, 20, 40, 20],
5
+ [0,60, 80, 40, 90],
6
+ [0,140, 120, 120, ],
7
+ ]
8
+ df = pd.DataFrame(list)
9
+ df
10
+
11
+ from sklearn.linear_model import LinearRegression
12
+ def pred(df):
13
+ x_train = df.iloc[0:df.shape[0]-1, 0:df.shape[1]-1]
14
+ y_train = df.iloc[0:df.shape[0]-1, df.shape[1]-1]
15
+ # x_test = [df.iloc[0:df.shape[0]-1, 0:df.shape[1]-1]]
16
+ x_test = [df.iloc[df.shape[0]-1, 0:df.shape[1]-1]]
17
+ model_lr = LinearRegression()
18
+ model_lr.fit(x_train, y_train)
19
+ return model_lr.predict(x_test)
20
+ pred(df.T)
21
+ #array([138.])
22
+
1
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-10-02/77358063-4079-471c-9921-35d80a5c9308.jpeg)
23
+ ```![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-10-02/77358063-4079-471c-9921-35d80a5c9308.jpeg)
2
24
 
3
25
  このエラーはどのようにして改善すれば良いですか?データ右下の空欄を回帰分析で求めるようにしたいです