일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- javascript
- 알고리즘
- pycharm
- DFS
- index
- ipad
- SciPy
- pandas
- Python
- E-P1
- GT-S80
- mean
- synology
- 삼성소프트웨어멤버십
- Numpy
- LSTM
- CNN
- GitHub
- Series
- install
- SPL
- Button
- Splunk
- RNN
- Lotto
- dataframe
- pip
- keras
- mariadb
- imread
Archives
- Today
- Total
잠토의 잠망경
[ML] Multi-step CNN Models 본문
GITHUB
https://github.com/yiwonjae/Project_Lotto/blob/master/Book_001/p111.py
0. 목표
output이 여러단계를 원할 때
1. DATA
raw_seq = [10, 20, 30, 40, 50, 60, 70, 80, 90]
2. DATA 정제
X
from numpy import ndarray
import numpy as np
def split_sequence(sequence:list, n_steps_in:int, n_steps_out:int)->(ndarray, ndarray):
x = []
y = []
for i in range(len(sequence)):
if(i+n_steps_in+n_steps_out > len(sequence)):
break
x.append(sequence[i:i+n_steps_in])
y.append(sequence[i+n_steps_in : i+n_steps_in + n_steps_out])
return (np.asarray(x), np.asarray(y))
n_steps_in = 3
n_steps_out = 2
(x, y) = split_sequence(raw_seq, n_steps_in, n_steps_out)
print(x.shape)
print(y.shape)
n_feature = 1
x = x.reshape((x.shape[0], x.shape[1], n_feature))
3. 학습
from keras import Sequential
from keras.layers import Dense, Conv1D, MaxPool1D, Flatten
model = Sequential()
model.add(Conv1D(64, 2, activation='relu', input_shape=(n_steps_in, n_feature)))
model.add(MaxPool1D())
model.add(Flatten())
model.add(Dense(50, activation='relu'))
model.add(Dense(n_steps_out))
model.compile(optimizer='adam', loss='mse')
model.fit(x, y, epochs=2000, verbose=1)
4. 표시
x_input = np.asarray([70, 80, 90])
x_input = x_input.reshape((1, n_steps_in, n_feature))
yhat = model.predict(x_input, verbose=1) # expect : [100, 110]
print(yhat) #[[102.19693 113.60678]]