質問編集履歴
3
コード追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
python エラー
|
1
|
+
python エラー 未来の株価と比較
|
test
CHANGED
File without changes
|
2
文法修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,87 +1,247 @@
|
|
1
1
|
Google Colaboratory にて、株のS&P500種指数データを予想する。コードを練習中なのですが、エラー内容が24の範囲外なのでエラーです。的なことが出てるのですが、多分以下のコードらへんからおかしいと思われるのですが、どこのコードの数字を変更すれば良いのか。わからないため、ご教授お願いいたします。
|
2
2
|
|
3
|
+
|
4
|
+
|
5
|
+
```
|
6
|
+
|
7
|
+
for epoch in range(epochs):
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
print()
|
12
|
+
|
13
|
+
print(f'Epoch: {epoch+1}')
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
run_train()
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
extending_seq = train_seq[-test_size:].tolist()
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
run_test()
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
plt.figure(figsize=(12, 4))
|
30
|
+
|
31
|
+
plt.xlim(-20, len(y)+20)
|
32
|
+
|
33
|
+
plt.grid(True)
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
plt.plot(y.numpy())
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
plt.plot(
|
42
|
+
|
43
|
+
range(len(y)-test_size, len(y)),
|
44
|
+
|
45
|
+
extending_seq[-test_size:]
|
46
|
+
|
47
|
+
)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
plt.show()
|
52
|
+
|
53
|
+
```
|
54
|
+
|
55
|
+
↓
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
plt.plot(train_losses)
|
60
|
+
|
61
|
+
```
|
62
|
+
|
63
|
+
↓
|
64
|
+
|
65
|
+
```
|
66
|
+
|
67
|
+
plt.plot(test_losses)
|
68
|
+
|
69
|
+
```
|
70
|
+
|
71
|
+
↓
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
predicted_normalized_labels_list = extending_seq[-test_size:]
|
76
|
+
|
77
|
+
```
|
78
|
+
|
79
|
+
↓
|
80
|
+
|
81
|
+
```
|
82
|
+
|
83
|
+
predicted_normalized_labels_array_1d = np.array(predicted_normalized_labels_list)
|
84
|
+
|
85
|
+
predicted_normalized_labels_array_1d
|
86
|
+
|
87
|
+
```
|
88
|
+
|
89
|
+
↓
|
90
|
+
|
91
|
+
```
|
92
|
+
|
93
|
+
predicted_normalized_labels_array_2d = predicted_normalized_labels_array_1d.reshape(-1, 1)
|
94
|
+
|
95
|
+
predicted_normalized_labels_array_2d
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
↓
|
100
|
+
|
101
|
+
```
|
102
|
+
|
103
|
+
predicted_labels_array_2d = scaler.inverse_transform(predicted_normalized_labels_array_2d)
|
104
|
+
|
105
|
+
predicted_labels_array_2d
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
↓
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
len(predicted_labels_array_2d)
|
114
|
+
|
115
|
+
```
|
116
|
+
|
117
|
+
↓
|
118
|
+
|
119
|
+
```
|
120
|
+
|
121
|
+
stock_data["Adj Close"][-test_size:]
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
↓
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
len(stock_data["Adj Close"][-test_size:])
|
130
|
+
|
131
|
+
```
|
132
|
+
|
133
|
+
↓
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
stock_data.index
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
↓
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
x_2018_10_to_2020_09 = np.arange('2018-10', '2020-10', dtype='datetime64[M]')
|
146
|
+
|
147
|
+
x_2018_10_to_2020_09
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
↓
|
152
|
+
|
153
|
+
```
|
154
|
+
|
155
|
+
len(x_2018_10_to_2020_09)
|
156
|
+
|
157
|
+
```
|
158
|
+
|
159
|
+
↓
|
160
|
+
|
161
|
+
```
|
162
|
+
|
163
|
+
fig = plt.figure(figsize=(12, 4))
|
164
|
+
|
165
|
+
plt.title('S$P500 prediction with test data')
|
166
|
+
|
167
|
+
plt.ylabel('Price')
|
168
|
+
|
169
|
+
plt.grid(True)
|
170
|
+
|
171
|
+
plt.autoscale(axis='x', tight=True)
|
172
|
+
|
173
|
+
fig.autofmt_xdate()
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
plt.plot(stock_data["Adj Close"]['2016-01':])
|
178
|
+
|
179
|
+
plt.plot(x_2018_10_to_2020_09, predicted_labels_array_2d)
|
180
|
+
|
181
|
+
plt.show()
|
182
|
+
|
183
|
+
```
|
184
|
+
|
185
|
+
↓
|
186
|
+
|
187
|
+
```
|
188
|
+
|
189
|
+
stock_data["Adj Close"]['2018-10':]
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
↓
|
194
|
+
|
195
|
+
```
|
196
|
+
|
197
|
+
len(stock_data["Adj Close"]['2018-10':])
|
198
|
+
|
199
|
+
```
|
200
|
+
|
201
|
+
↓
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
real_labels_array_1d = stock_data["Adj Close"]['2018-10':].values
|
206
|
+
|
207
|
+
real_labels_array_1d
|
208
|
+
|
209
|
+
```
|
210
|
+
|
211
|
+
↓
|
212
|
+
|
213
|
+
```
|
214
|
+
|
215
|
+
predicted_labels_array_2d
|
216
|
+
|
217
|
+
```
|
218
|
+
|
219
|
+
↓
|
220
|
+
|
221
|
+
```
|
222
|
+
|
223
|
+
predicted_labels_array_1d = predicted_labels_array_2d.flatten()
|
224
|
+
|
225
|
+
predicted_labels_array_1d
|
226
|
+
|
227
|
+
```
|
228
|
+
|
229
|
+
↓
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
len(predicted_labels_array_1d)
|
234
|
+
|
235
|
+
```
|
236
|
+
|
237
|
+
↓
|
238
|
+
|
239
|
+
↓
|
240
|
+
|
241
|
+
|
242
|
+
|
3
243
|
```python
|
4
244
|
|
5
|
-
fig = plt.figure(figsize=(12, 4))
|
6
|
-
|
7
|
-
plt.title('S$P500 prediction with test data')
|
8
|
-
|
9
|
-
plt.ylabel('Price')
|
10
|
-
|
11
|
-
plt.grid(True)
|
12
|
-
|
13
|
-
plt.autoscale(axis='x', tight=True)
|
14
|
-
|
15
|
-
fig.autofmt_xdate()
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
plt.plot(stock_data["Adj Close"]['2016-01':])
|
20
|
-
|
21
|
-
plt.plot(x_2018_10_to_2020_09, predicted_labels_array_2d)
|
22
|
-
|
23
|
-
plt.show()
|
24
|
-
|
25
|
-
```
|
26
|
-
|
27
|
-
↓
|
28
|
-
|
29
|
-
```python
|
30
|
-
|
31
|
-
stock_data["Adj Close"]['2018-10':]
|
32
|
-
|
33
|
-
```
|
34
|
-
|
35
|
-
↓
|
36
|
-
|
37
|
-
```python
|
38
|
-
|
39
|
-
len(stock_data["Adj Close"]['2018-10':])
|
40
|
-
|
41
|
-
↓
|
42
|
-
|
43
|
-
27
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
```python
|
48
|
-
|
49
|
-
real_labels_array_1d = stock_data["Adj Close"]['2018-10':].values
|
50
|
-
|
51
|
-
real_labels_array_1d
|
52
|
-
|
53
|
-
```
|
54
|
-
|
55
|
-
↓
|
56
|
-
|
57
|
-
```python
|
58
|
-
|
59
|
-
predicted_labels_array_2d
|
60
|
-
|
61
|
-
```
|
62
|
-
|
63
|
-
↓
|
64
|
-
|
65
|
-
```python
|
66
|
-
|
67
|
-
predicted_labels_array_1d = predicted_labels_array_2d.flatten()
|
68
|
-
|
69
|
-
predicted_labels_array_1d
|
70
|
-
|
71
|
-
```
|
72
|
-
|
73
|
-
↓
|
74
|
-
|
75
|
-
```python
|
76
|
-
|
77
|
-
len(predicted_labels_array_1d)
|
78
|
-
|
79
|
-
```
|
80
|
-
|
81
|
-
↓
|
82
|
-
|
83
|
-
```python
|
84
|
-
|
85
245
|
up_and_down_list = []
|
86
246
|
|
87
247
|
|
1
コード追加
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
python エラー
|
1
|
+
python エラー 解決策
|
test
CHANGED
File without changes
|