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

質問編集履歴

2

配置の変更

2021/07/04 16:25

投稿

n_r
n_r

スコア1

title CHANGED
File without changes
body CHANGED
@@ -7,55 +7,74 @@
7
7
  ### 発生している問題・エラーメッセージ
8
8
  ValueError: Found input variables with inconsistent numbers of samples: [8770, 2619]
9
9
  ```
10
- エラーメッセージ
10
+ エラーメッセージ---------------------------------------------------------------------------
11
- ```ValueError: Found input variables with inconsistent numbers of samples: [8770, 2619]
11
+ ValueError Traceback (most recent call last)
12
+ <ipython-input-14-c1afc537bce1> in <module>()
13
+ 20
14
+ 21 # 予測結果(スコア)
15
+ ---> 22 Score = 'Score =' + str(model.score(x_test,y_test))
16
+ 23 print(Score)
17
+ 24
12
18
 
19
+ 2 frames
20
+ /usr/local/lib/python3.7/dist-packages/sklearn/utils/validation.py in check_consistent_length(*arrays)
21
+ 210 if len(uniques) > 1:
22
+ 211 raise ValueError("Found input variables with inconsistent numbers of"
23
+ --> 212 " samples: %r" % [int(l) for l in lengths])
24
+ 213
25
+ 214
26
+
27
+ ValueError: Found input variables with inconsistent numbers of samples: [8770, 2619]
28
+ ```
29
+
13
30
  ### 該当のソースコード
14
31
 
15
32
  ```ここに言語名を入力
16
- ソースコード
17
- ``` 検証用データ(2019年度電力需要)の読み込み
33
+ ソースコード# 検証用データ(2019年度電力需要)の読み込み
18
34
  filename = "/content/drive/MyDrive/Colab Notebooks/2019 .csv"
19
35
  df = pd.read_csv(filename,encoding="SHIFT-JIS")
20
36
 
21
37
  df = df.dropna()
22
38
 
23
- 検証用データの説明変数とするデータ列の指定
39
+ # 検証用データの説明変数とするデータ列の指定
24
40
  x = ['Month', 'Week', 'Hour', 'Asa_Temp', 'Hako_Temp', 'Toma_Temp', 'Kushi_Temp', 'Aba_Temp']
25
- 検証用データの目的変数とするデータ列の指定
41
+ # 検証用データの目的変数とするデータ列の指定
26
42
  y = ['Power']
27
43
 
28
- それぞれの数値型を指定
44
+ # それぞれの数値型を指定
29
45
  x = df[x].values.astype('float')
30
46
  y = df[y].values.astype('int').flatten()
31
47
  x_test = scaler.transform(x_test)
32
48
  y_test = y
33
49
 
34
- 予測
50
+ # 予測
35
51
  result = model.predict(x)
36
52
 
37
- 予測結果(スコア)
53
+ # 予測結果(スコア)
38
54
  Score = 'Score =' + str(model.score(x_test,y_test))
39
55
  print(Score)
40
56
 
41
- グラフの準備
57
+ # グラフの準備
42
- データシートへの予測結果と年月日時刻の追加
58
+ # データシートへの予測結果と年月日時刻の追加
43
59
  df['PrePower'] = result
44
60
  df['Datetime'] = pd.to_datetime(df[['Year', 'Month', 'Day', 'Hour']])
45
61
 
46
- グラフ
62
+ # グラフ
47
63
  plt.figure(figsize=(16,4),facecolor='white')
48
64
  plt.title(MLname, size=16)
49
65
  plt.xlabel('Time')
50
66
  plt.ylabel('Demand (x10,000 kW)')
51
67
  plt.xlim(dt.datetime(2019,4,1,0), dt.datetime(2020,3,31,23))
52
- plt.xlim(datetime.datetime(2019,4,1,0), datetime.datetime(2019,4,2,23))
68
+ # plt.xlim(datetime.datetime(2019,4,1,0), datetime.datetime(2019,4,2,23))
53
69
  plt.grid(True)
54
70
  plt.plot(df['Datetime'], df['Power'], label='Act',linewidth = 0.7)
55
71
  plt.plot(df['Datetime'], df['PrePower'], label='Pre',linewidth = 0.7)
56
72
  plt.legend(loc='upper right')
57
73
  plt.text(dt.datetime(2019,4,2,0), 470, Score, size=14)
58
74
 
75
+ # 作成したグラフの保存
76
+ plt.savefig("/content/drive/MyDrive/Colab Notebooks/Result.png")
77
+ ```
59
78
  ### 試したこと
60
79
 
61
80
  ここに問題に対して試したことを記載してください。

1

誤字

2021/07/04 16:25

投稿

n_r
n_r

スコア1

title CHANGED
File without changes
body CHANGED
@@ -14,42 +14,42 @@
14
14
 
15
15
  ```ここに言語名を入力
16
16
  ソースコード
17
- ```# 検証用データ(2019年度電力需要)の読み込み
17
+ ``` 検証用データ(2019年度電力需要)の読み込み
18
18
  filename = "/content/drive/MyDrive/Colab Notebooks/2019 .csv"
19
19
  df = pd.read_csv(filename,encoding="SHIFT-JIS")
20
20
 
21
21
  df = df.dropna()
22
22
 
23
- # 検証用データの説明変数とするデータ列の指定
23
+ 検証用データの説明変数とするデータ列の指定
24
24
  x = ['Month', 'Week', 'Hour', 'Asa_Temp', 'Hako_Temp', 'Toma_Temp', 'Kushi_Temp', 'Aba_Temp']
25
- # 検証用データの目的変数とするデータ列の指定
25
+ 検証用データの目的変数とするデータ列の指定
26
26
  y = ['Power']
27
27
 
28
- # それぞれの数値型を指定
28
+ それぞれの数値型を指定
29
29
  x = df[x].values.astype('float')
30
30
  y = df[y].values.astype('int').flatten()
31
31
  x_test = scaler.transform(x_test)
32
32
  y_test = y
33
33
 
34
- # 予測
34
+ 予測
35
35
  result = model.predict(x)
36
36
 
37
- # 予測結果(スコア)
37
+ 予測結果(スコア)
38
38
  Score = 'Score =' + str(model.score(x_test,y_test))
39
39
  print(Score)
40
40
 
41
- # グラフの準備
41
+ グラフの準備
42
- # データシートへの予測結果と年月日時刻の追加
42
+ データシートへの予測結果と年月日時刻の追加
43
43
  df['PrePower'] = result
44
44
  df['Datetime'] = pd.to_datetime(df[['Year', 'Month', 'Day', 'Hour']])
45
45
 
46
- # グラフ
46
+ グラフ
47
47
  plt.figure(figsize=(16,4),facecolor='white')
48
48
  plt.title(MLname, size=16)
49
49
  plt.xlabel('Time')
50
50
  plt.ylabel('Demand (x10,000 kW)')
51
51
  plt.xlim(dt.datetime(2019,4,1,0), dt.datetime(2020,3,31,23))
52
- # plt.xlim(datetime.datetime(2019,4,1,0), datetime.datetime(2019,4,2,23))
52
+ plt.xlim(datetime.datetime(2019,4,1,0), datetime.datetime(2019,4,2,23))
53
53
  plt.grid(True)
54
54
  plt.plot(df['Datetime'], df['Power'], label='Act',linewidth = 0.7)
55
55
  plt.plot(df['Datetime'], df['PrePower'], label='Pre',linewidth = 0.7)