3번째 줄: |
3번째 줄: |
| | | |
| 현재일을 포함한 50일 거래일의 데이터를 바탕으로 이후의 값을 예측. 일반적으로 OHLCV를 넣어준다. | | 현재일을 포함한 50일 거래일의 데이터를 바탕으로 이후의 값을 예측. 일반적으로 OHLCV를 넣어준다. |
| + | |
| + | === 요구사항 === |
| + | 케라스와 텐서플로우, 판다스, 넘파이 따위의 라이브러리를 필요로 한다. |
| | | |
| == 사용 == | | == 사용 == |
16번째 줄: |
19번째 줄: |
| import numpy as np | | import numpy as np |
| import FinanceDataReader as fdr # 주가데이터를 알려주는 라이브러리. | | import FinanceDataReader as fdr # 주가데이터를 알려주는 라이브러리. |
− | form sklearn import preprocessing # 사이킷런의 데이터 전처리 기능을 이용한다.
| |
| </syntaxhighlight> | | </syntaxhighlight> |
| |- | | |- |
22번째 줄: |
24번째 줄: |
| |데이터를 불러와 50개씩 나누어 교육데이터를 준비한다. | | |데이터를 불러와 50개씩 나누어 교육데이터를 준비한다. |
| |<syntaxhighlight lang="python"> | | |<syntaxhighlight lang="python"> |
| + | from sklearn import preprocessing # 사이킷런의 데이터 전처리 기능을 이용한다. |
| + | |
| def call_dataset(ticker = '005930', stt = '2015-01-01', end = '2021-03-30', history_points = 50): | | def call_dataset(ticker = '005930', stt = '2015-01-01', end = '2021-03-30', history_points = 50): |
| data = fdr.DataReader(ticker, stt, end) | | data = fdr.DataReader(ticker, stt, end) |
27번째 줄: |
31번째 줄: |
| print('data: ', data.shape) | | print('data: ', data.shape) |
| data = data.values # 값만 갖고온다 | | data = data.values # 값만 갖고온다 |
− | data_normalizer = preprocessing.MinMaxScaler() # 데이터를 0~1 범위로 점철되게 하는 함수 call | + | data_normalizer = preprocessing.MinMaxScaler() # 데이터를 0~1 범위로 전처리 하는 함수 call |
− | data_normalized = data_normalizer.fit_transform(data) # 데이터를 0~1 범위로 점철되게 함수 수행 | + | data_normalized = data_normalizer.fit_transform(data) # 데이터를 0~1 범위로 전처리 |
| print('data_normalized: ', data_normalized.shape) | | print('data_normalized: ', data_normalized.shape) |
| # using the last {history_points} open close high low volume data points, predict the next open value | | # using the last {history_points} open close high low volume data points, predict the next open value |
91번째 줄: |
95번째 줄: |
| | | |
| import keras | | import keras |
− | from keras.models import Model
| |
− | from keras.layers import Dense, Dropout, LSTM, Input, Activation
| |
− | from keras import optimizers
| |
| import numpy as np | | import numpy as np |
| np.random.seed(4) | | np.random.seed(4) |
124번째 줄: |
125번째 줄: |
| | | | | |
| |<syntaxhighlight lang="python"> | | |<syntaxhighlight lang="python"> |
| + | from keras.models import Model |
| + | from keras.layers import Dense, Dropout, LSTM, Input, Activation |
| + | from keras import optimizers |
| + | |
| # model architecture | | # model architecture |
| lstm_input = Input(shape=(history_points, 5), name='lstm_input') | | lstm_input = Input(shape=(history_points, 5), name='lstm_input') |