Created
July 28, 2019 17:21
-
-
Save DPS0340/4c914d0eb278c007472ad22e08201c4a to your computer and use it in GitHub Desktop.
why predict value is too low
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from keras.layers.core import Dense, Activation, Dropout | |
| from keras.layers.recurrent import LSTM | |
| from keras.models import Sequential | |
| from numpy import newaxis | |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| from keras.layers.core import Dense, Activation, Dropout | |
| from sklearn.model_selection import train_test_split | |
| import time | |
| def nomalization(arr): | |
| result = [] | |
| pivot = arr[0] | |
| result.append(1) | |
| for elem in arr[1:]: | |
| result.append(elem / pivot) | |
| result = np.array(result) | |
| result = result[..., newaxis] | |
| return result | |
| data = np.genfromtxt('./data/삼성전자.csv') | |
| data = np.array(nomalization(data)) | |
| days = np.array(range(0, len(data))) | |
| data = np.array([[a] for a in data]) | |
| days = np.array([[a] for a in days]) | |
| print(data.shape) | |
| print(days.shape) | |
| X_train, X_test, Y_train, Y_test = train_test_split(data, days, test_size=0.3, random_state=0) | |
| model = Sequential() | |
| model.add(LSTM( | |
| input_dim=1, | |
| output_dim=50, | |
| return_sequences=True)) | |
| model.add(Dropout(0.2)) | |
| model.add(LSTM( | |
| 100, | |
| return_sequences=False)) | |
| model.add(Dropout(0.2)) | |
| model.add(Dense( | |
| output_dim=1)) | |
| model.add(Activation('linear')) | |
| start = time.time() | |
| model.compile(loss='mse', optimizer='rmsprop') | |
| print('compilation time : ', time.time() - start) | |
| model.fit( | |
| X_train, | |
| Y_train, | |
| batch_size=1024, | |
| nb_epoch=5, | |
| validation_split=0.05) | |
| def predict_sequences_multiple(model, data, window_size, prediction_len): | |
| return model.predict(data) | |
| predictions = predict_sequences_multiple(model, X_test, 30, 30) | |
| for i in range(len(predictions)): | |
| print("true: %s" % (X_test[i])) | |
| print("prediction: %s" % (predictions[i])) | |
| print("delta: %s" % (X_test[i] - predictions[i])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment