質問編集履歴
3
個人情報が含まれていた。気分を害する回答がきた。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2値分類タスク
|
1
|
+
2値分類タスクの学習,
|
test
CHANGED
File without changes
|
2
個人情報が含まれていた。気分を害する回答がきた。
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,201 +1 @@
|
|
1
|
-
60ステップの価格系列(Close)を入力データとし、次の時刻の価格(Close)が下がるか上がるかを分類するタスクです。
|
2
|
-
|
3
|
-
以下のようにモデルを作成したのですが、学習が進みません。
|
4
|
-
|
5
|
-
データ(all_data)は以下のようになっています。
|
6
|
-
|
7
|
-
| index(時刻) |Open|High|Low|Close|Adj Close|Volume
|
8
|
-
|
9
|
-
|:--|:--:|--:|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
データ作成
|
14
|
-
|
15
|
-
```python
|
16
|
-
|
17
|
-
def create_dl_train_test_split(all_data,OHLC='Close',look_back=60):
|
18
|
-
|
19
|
-
all_data[OHLC+'_diff'] = all_data[OHLC].diff()
|
20
|
-
|
21
|
-
all_data['RS'] = all_data[OHLC+'_diff'].map(lambda x: 1 if x>0 else 0)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
#Nanの値を削除
|
26
|
-
|
27
|
-
all_data = all_data.dropna(subset=[OHLC+'_diff'])
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
#分割
|
32
|
-
|
33
|
-
train_set_X = all_data['1990':'2016'].iloc[:, 6:7].values
|
34
|
-
|
35
|
-
train_set_y = all_data['1990':'2016'].iloc[:, 7:8].values
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
test_set_X = all_data['2017':].iloc[:, 6:7].values
|
40
|
-
|
41
|
-
test_set_y = all_data['2017':].iloc[:, 7:8].values
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
scaler = StandardScaler()
|
46
|
-
|
47
|
-
scaler.fit(train_set_X)
|
48
|
-
|
49
|
-
train_set_scaled = scaler.transform(train_set_X)
|
50
|
-
|
51
|
-
test_set_scaled = scaler.transform(test_set_X)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
# 翌日の価格を予測するために、過去60日分のデータを使用
|
58
|
-
|
59
|
-
X_train = []
|
60
|
-
|
61
|
-
y_train = []
|
62
|
-
|
63
|
-
X_test = []
|
64
|
-
|
65
|
-
y_test = []
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
for i in range(look_back, len(train_set_X)):
|
70
|
-
|
71
|
-
X_train.append(train_set_scaled[i - look_back:i, 0])
|
72
|
-
|
73
|
-
y_train.append(train_set_y[i, 0])
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
for i in range(look_back, len(test_set_X)):
|
78
|
-
|
79
|
-
X_test.append(test_set_scaled[i - look_back:i, 0])
|
80
|
-
|
81
|
-
y_test.append(test_set_y[i, 0])
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
1
|
+
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
86
|
-
|
87
|
-
X_test, y_test = np.array(X_test), np.array(y_test)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
X_train = np.reshape(X_train, (X_train.shape[0], X_train.shape[1], 1))
|
92
|
-
|
93
|
-
X_test = np.reshape(X_test, (X_test.shape[0], X_test.shape[1], 1))
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
#学習データから8:2の割合で 検証データを作る
|
98
|
-
|
99
|
-
X_train, X_val, y_train, y_val = train_test_split(X_train,y_train, test_size=0.2)
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
return X_train, y_train, X_val, y_val, X_test, y_test, scaler
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
```
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
モデル作成
|
112
|
-
|
113
|
-
```Python
|
114
|
-
|
115
|
-
def create_LSTM_with_drop_out_model(X_train, y_train, X_val, y_val, X_test,):
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
model = Sequential()
|
120
|
-
|
121
|
-
model.add(LSTM(units=25, activation='tanh', recurrent_activation='sigmoid', kernel_initializer='glorot_normal',
|
122
|
-
|
123
|
-
recurrent_initializer='orthogonal', return_sequences=False, input_shape=(X_train.shape[1],1)))
|
124
|
-
|
125
|
-
model.add(Dropout(0.2))
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
model.add(Dense(units=1, activation='sigmoid'))
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
optimizer = Adam(learning_rate=0.001)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
es = EarlyStopping(monitor='val_loss', patience=50, verbose=1)
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
model.compile(optimizer=optimizer, loss='binary_crossentropy', metrics=['accuracy'])
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
model.fit(X_train, y_train, epochs=100, batch_size=128, verbose=1, validation_data=(X_val, y_val), callbacks=[es])
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
predicted = model.predict(X_test)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
return model,predicted
|
154
|
-
|
155
|
-
```
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
実行すると
|
162
|
-
|
163
|
-
Train on 5104 samples, validate on 1276 samples
|
164
|
-
|
165
|
-
Epoch 1/100
|
166
|
-
|
167
|
-
5104/5104 [==============================] - 4s 778us/sample - loss: 0.6938 - accuracy: 0.5096 - val_loss: 0.6936 - val_accuracy: 0.4867
|
168
|
-
|
169
|
-
Epoch 2/100
|
170
|
-
|
171
|
-
5104/5104 [==============================] - 2s 336us/sample - loss: 0.6932 - accuracy: 0.5125 - val_loss: 0.6926 - val_accuracy: 0.4937
|
172
|
-
|
173
|
-
Epoch 3/100
|
174
|
-
|
175
|
-
5104/5104 [==============================] - 2s 341us/sample - loss: 0.6924 - accuracy: 0.5135 - val_loss: 0.6924 - val_accuracy: 0.4945
|
176
|
-
|
177
|
-
Epoch 4/100
|
178
|
-
|
179
|
-
5104/5104 [==============================] - 2s 341us/sample - loss: 0.6919 - accuracy: 0.5161 - val_loss: 0.6927 - val_accuracy: 0.4969
|
180
|
-
|
181
|
-
Epoch 5/100
|
182
|
-
|
183
|
-
5104/5104 [==============================] - 2s 331us/sample - loss: 0.6918 - accuracy: 0.5159 - val_loss: 0.6929 - val_accuracy: 0.4945
|
184
|
-
|
185
|
-
Epoch 6/100
|
186
|
-
|
187
|
-
5104/5104 [==============================] - 2s 333us/sample - loss: 0.6920 - accuracy: 0.5182 - val_loss: 0.6931 - val_accuracy: 0.4929
|
188
|
-
|
189
|
-
Epoch 7/100
|
190
|
-
|
191
|
-
5104/5104 [==============================] - 2s 349us/sample - loss: 0.6919 - accuracy: 0.5182 - val_loss: 0.6929 - val_accuracy: 0.4953
|
192
|
-
|
193
|
-
Epoch 8/100
|
194
|
-
|
195
|
-
5104/5104 [==============================] - 2s 328us/sample - loss: 0.6917 - accuracy: 0.5165 - val_loss: 0.6931 - val_accuracy: 0.4929
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
と一向に損失関数が減らず学習が進まないです。
|
200
|
-
|
201
|
-
解決方法がわかる方がいましたらぜひお願いします。
|
1
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
60ステップの価格系列(Close)を入力データとし、次の時刻の価格(Close)が下がるか上がるかを分類するタスクです。
|
2
2
|
|
3
|
-
以下のようにモデルを作成したのですが、学習
|
3
|
+
以下のようにモデルを作成したのですが、学習が進みません。
|
4
4
|
|
5
5
|
データ(all_data)は以下のようになっています。
|
6
6
|
|
@@ -108,6 +108,8 @@
|
|
108
108
|
|
109
109
|
|
110
110
|
|
111
|
+
モデル作成
|
112
|
+
|
111
113
|
```Python
|
112
114
|
|
113
115
|
def create_LSTM_with_drop_out_model(X_train, y_train, X_val, y_val, X_test,):
|