現在、ディープラーニングを用いてAPPLEの2000年から2018年の株価データを用いて2018年から2019年の株価データを予測するプログラムを作成しています。その中で学習過程で損失係数が一切下がらず、正解率が0%になってしまいました。
私自身、機械学習・深層学習経験があまりないので以下のコードは様々なサイト等を参考にして作成したものです。そこでどこを直せば損失率を下げることができ、正解率を上げることができるのかお分かりになる方がおりましたら教えていただきたいです。
いかにコードを記載します。
Python
1import keras 2import pandas as pd 3import numpy as np 4import matplotlib.pyplot as plt 5from pandas_datareader import data 6import tensorflow as tf 7from datetime import datetime 8 9#Keras-Sequential-model 10from keras.models import Sequential 11from keras.callbacks import EarlyStopping 12#layer 13from keras.layers import Dense, Dropout, Activation 14#Parameter update 15from keras.optimizers import RMSprop, SGD, Adam 16%matplotlib inline 17 18#データ設定 19train_start = '2010-04-01' 20train_end = '2018-03-31' 21test_start = '2018-04-01' 22test_end = '2019-03-31' 23 24df_train = data.DataReader('AAPL', 'yahoo', train_start, train_end) 25df_test = data.DataReader('AAPL', 'yahoo', test_start, test_end) 26 27#日時と調整終了値 28past_date = df_train.index 29past_price = df_train['Adj Close'] 30future_date = df_test.index 31future_price = df_test['Adj Close'] 32 33#ディープラーニングモデル 34def build_multilayer_perceptron(): 35 model = Sequential() 36 model.add(Dense(100, input_shape=(20,))) 37 model.add(Activation('relu')) 38 model.add(Dropout(0.2)) 39 model.add(Dense(100)) 40 model.add(Activation('relu')) 41 model.add(Dropout(0.2)) 42 model.add(Dense(1)) 43 model.add(Activation('softmax')) 44 model.compile(loss='mse', 45 optimizer='adam', 46 metrics=['accuracy']) 47 return model 48 49#標準化 50def getInputLabel(price, period=20): 51 period = period 52 input_tensor = [] 53 label_tensor = [] 54 for i in range(0, len(price) - period, 1): 55 input_tensor.append(price.iloc[i:i + period ]) 56 label_tensor.append(price.iloc[i + period ]) 57 input_tensor = np.array(input_tensor) 58 label_tensor = np.array(label_tensor) 59 return input_tensor, label_tensor 60 61#訓練用データとテスト用データ 62past_tmp = past_price - past_price.mean() 63past_tmp = past_tmp/past_price.std() 64X_train, y_train = getInputLabel(price = past_tmp) 65 66future_tmp = future_price - future_price.mean() 67future_tmp = future_tmp/future_price.std() 68X_test, y_test = getInputLabel(price = future_tmp) 69 70earlystopping = EarlyStopping(monitor='loss', patience=5) 71 72model = build_multilayer_perceptron() 73model.summary() 74 75#Learning 76history = model.fit(X_train, y_train, 77 batch_size=20, 78 epochs=100, 79 verbose=1, 80 validation_data=(X_test, y_test), 81 callbacks=[earlystopping]) 82 83>>> 84Epoch 1/100 85100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 86Epoch 2/100 87100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 88Epoch 3/100 89100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 90Epoch 4/100 91100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 92Epoch 5/100 93100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 94Epoch 6/100 95100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 96Epoch 7/100 97100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 98Epoch 8/100 99100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 100Epoch 9/100 101100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 102Epoch 10/100 103100/100 [==============================] - 0s 2ms/step - loss: 1.9591 - accuracy: 0.0000e+00 - val_loss: 1.8511 - val_accuracy: 0.0000e+00 104 105model.evaluate(X_test, y_test, verbose=0) 106>>>[1.851119041442871, 0.0] 107```
回答1件
あなたの回答
tips
プレビュー