P
P
Pantuchi2021-05-16 20:07:06
Neural networks
Pantuchi, 2021-05-16 20:07:06

Tanserflow + Keras + LSTM. What are the correct pre-settings?

Hello forumites. Help me figure out how to properly configure the LSTM network model. I have a dataset of meager 88 measurements. For myself, I made 22 time intervals with 4 values ​​in each.

Values ​​normalized by dividing all dataset values ​​by array.max

def learning(self, source: []):
        raw_seq = array([i for i in source])
        n_steps_in, n_steps_out = self.step_time, self.step_time_out
        X, y = self.__split_sequence(raw_seq, n_steps_in, n_steps_out)
        X = self.Normalize(X)
        y = self.Normalize(y)

        n_features = self.features
        X = X.reshape((X.shape[0], X.shape[1], n_features))

        self.model = Sequential()
        self.model.add(LSTM(100, activation='relu', return_sequences=True, input_shape=(n_steps_in, n_features)))
        self.model.add(LSTM(120, activation='relu'))
        self.model.add(Dense(n_steps_out))
        self.model.compile(optimizer='adam', loss='mae')

        self.model.fit(X, y, epochs=100, verbose=2)

    pass

def prediction(self, source: []):
        # x_input = array(source)
        x_input = array(self.Normalize(source))
        x_input = x_input.reshape((1, self.step_time, self.features))
        yhat = self.model.predict(x_input, verbose=2)
        return yhat

if __name__ == '__main__':
    train_x = load_from_excel(path_train, row=2, col=1, count=84, list='Все данные - Виброускорение') # 84 тестовых данных 22 тайм лайна из 4 значений каждый
    input_x = load_from_excel(path_resource, row=85, col=1, count=4, list='Все данные - Виброускорение') # 1 тайм лайн из 4 значений

    _lstm = MYLSTM(step_time_in=4, step_time_out=12, features=1) # 4 входных нейронов 12 выходных
    _lstm.learning(train_x)

    out = _lstm.prediction(input_x)
    # out = [i for i in out[0]]
    out = _lstm.scale([i for i in out[0]])
    print(out)

    write_in_excel(path_resource, list='Все данные - Виброускорение', row=93, col=1, out=out)

Epoch 1/100
3/3 - 2s - loss: 0.4913
Epoch 2/100
3/3 - 0s - loss: 0.4833
.....
Epoch 95/100
3/3 - 0s - loss: 0.1168
Epoch 96/100
3/ 3 - 0s - loss: 0.1180
Epoch 97/100
3/3 - 0s - loss: 0.1191
Epoch 98/100
3/3 - 0s - loss: 0.1171
Epoch 99/100
3/3 - 0s - loss: 0.1170
Epoch 100/100
3/3 - 0s - loss: 0.1163

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question