일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Series
- ipad
- javascript
- GT-S80
- Splunk
- Button
- SPL
- pandas
- index
- Python
- 알고리즘
- mean
- dataframe
- install
- SciPy
- mariadb
- keras
- GitHub
- RNN
- Lotto
- pip
- DFS
- imread
- Numpy
- E-P1
- synology
- LSTM
- pycharm
- 삼성소프트웨어멤버십
- CNN
Archives
- Today
- Total
잠토의 잠망경
[ML] LSTM - Univariate stack LSTM Models 본문
GITHUB
https://github.com/yiwonjae/Project_Lotto/blob/master/Book_001/p128.py
0. 목표
'''
data
[10, 20, 30, 40, 50, 60, 70, 80, 90]
X(input), y(output)
10, 20, 30, 40
20, 30, 40, 50
30, 40, 50, 60
'''
1. DATA
raw_seq = np.asarray([10, 20, 30, 40, 50, 60, 70, 80, 90])
2. DATA 정제
X
import numpy as np
from numpy import ndarray
def split_sequence(sequence:ndarray, n_steps:int)->(ndarray, ndarray):
x = []
y = []
for i in range(len(sequence)):
if(i+n_steps>=len(sequence)):
break
x.append(sequence[i:i+n_steps])
y.append(sequence[i+n_steps])
return (np.asarray(x), np.asarray(y))
raw_seq = np.asarray([10, 20, 30, 40, 50, 60, 70, 80, 90])
n_steps = 3
(x, y) = split_sequence(raw_seq, n_steps)
print(x.shape)
print(y.shape)
n_features = 1
x = x.reshape(x.shape[0], n_steps, n_features)
3. 학습
from keras import Sequential
from keras.layers import Dense, LSTM
model = Sequential()
model.add(LSTM(50, activation='relu', return_sequences=True, input_shape=(n_steps, n_features)))
model.add(LSTM(50, activation='relu'))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mse')
model.fit(x, y, epochs=200, verbose=1)
4. 표시
x_input = np.asarray([70, 80, 90]) # expect 100
x_input = x_input.reshape(1, n_steps, n_features)
yhat = model.predict(x_input, verbose=1)
print(yhat) # [[103.92277]]
Comments