Example #1
0
File: LSTM.py Project: zzy361/ROBO
            x_new_batch = scaled_data[-back_window:, :-1]
            x_new_batch = x_new_batch.reshape(1, x_new_batch.shape[0],
                                              x_new_batch.shape[1])
            pred = model.predict(x_new_batch)
            temp = [0] * new_batch.shape[1]
            temp[-1] = pred
            real_value_pred = batch_scale.inverse_transform([temp])[0][-1]
            return real_value_pred


if __name__ == '__main__':
    lstm = LSTM()
    df = pd.read_csv('000002-from-1995-01-01.csv')
    window = 20
    X_train, y_train, X_test, y_test = lstm.preprocess_data(df[::-1],
                                                            window,
                                                            predict_length=1,
                                                            split_percent=0.85)

    model = lstm.build_model([X_train.shape[2], window, 100, 1],
                             dropout=0.3,
                             problem_class='classification')
    encoder = LabelEncoder()
    encoded_Y = encoder.fit_transform(y_train)

    dummy_y = np_utils.to_categorical(encoded_Y)
    model.fit(X_train,
              dummy_y,
              batch_size=768,
              nb_epoch=10,
              validation_split=0.1,
              verbose=1)