일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- CNN
- index
- LSTM
- 알고리즘
- synology
- DFS
- Splunk
- pip
- mariadb
- Button
- ipad
- RNN
- Numpy
- SciPy
- 삼성소프트웨어멤버십
- dataframe
- Python
- mean
- pycharm
- GT-S80
- Lotto
- imread
- pandas
- GitHub
- SPL
- Series
- javascript
- E-P1
- keras
- install
Archives
- Today
- Total
잠토의 잠망경
[ML] Multiple Input Multi-step Output 본문
GITHUB
https://github.com/yiwonjae/Project_Lotto/blob/master/Book_001/p113.py
0. 목표
input 多, output 多step
1. DATA
in_seq1 = np.asarray([10, 20, 30, 40, 50, 60, 70, 80, 90])
in_seq2 = np.asarray([15, 25, 35, 45, 55, 65, 75, 85, 95])
out_seq = np.asarray([in_seq1[i]+in_seq2[i] for i in range(len(in_seq1))])
in_seq1:ndarray = in_seq1.reshape((len(in_seq1), 1))
in_seq2:ndarray = in_seq2.reshape((len(in_seq2), 1))
out_seq:ndarray = out_seq.reshape((len(out_seq), 1))
dataset = np.hstack((in_seq1, in_seq2, out_seq))
2. DATA 정제
X
from numpy import ndarray
import numpy as np
def split_sequence(sequence:ndarray, n_step_in:int, n_step_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, 0:2])
y.append(sequence[i+n_steps_in:i+n_steps_in+n_steps_out, -1])
return (np.asarray(x), np.asarray(y))
n_steps_in = 3
n_steps_out = 2
(x, y) = split_sequence(dataset, n_steps_in, n_steps_out)
print(x.shape)
n_feature = x.shape[2]
3. 학습
from keras import Sequential
from keras.layers import Dense, Flatten
from keras.layers.convolutional import Conv1D, MaxPooling1D
model = Sequential()
model.add(Conv1D(64, 2, activation='relu', input_shape=(n_steps_in, n_feature)))
model.add(MaxPooling1D())
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, batch_size=10, epochs=3000, verbose=1)
4. 표시
x_input = np.asarray([[70, 75],[80,85],[90,95]]) # expect [185, 205].
x_input = x_input.reshape((1, n_steps_in, n_feature))
yhat = model.predict(x_input, verbose=1)
print(yhat) #[[208.41682 230.64803]]
Comments