epochs = 1 seq_len = 50 print('> Loading data... ') X_train, y_train, X_test, y_test = read_csv('../file//others//sp500.csv', seq_len, True) print('X_train shape:', X_train.shape) #(3709L, 50L, 1L) print('y_train shape:', y_train.shape) #(3709L,) print('X_test shape:', X_test.shape) #(412L, 50L, 1L) print('y_test shape:', y_test.shape) #(412L,) print('> Data Loaded. Compiling...') model = LSTM.build_model([1, 50, 100, 1]) model.fit(X_train, y_train, batch_size=512, nb_epoch=epochs, validation_split=0.05) multiple_predictions = lstm.predict_sequences_multiple(model, X_test, seq_len, prediction_len=50) print('multiple_predictions shape:', np.array(multiple_predictions).shape) #(8L,50L) full_predictions = lstm.predict_sequence_full(model, X_test, seq_len)
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) diff = [] ratio = [] pred = model.predict(X_test) for u in range(len(y_test)):