Created
July 6, 2020 03:32
-
-
Save shashankvemuri/57fcce5fabfed87bd83cdef5d93efee9 to your computer and use it in GitHub Desktop.
train the model and get the predictions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #build LSTM model | |
| model = Sequential() | |
| model.add(LSTM(50, return_sequences=True, input_shape=(x_train.shape[1],1))) | |
| model.add(LSTM(50,return_sequences=False)) | |
| model.add(Dense(25)) | |
| model.add(Dense(1)) | |
| #compile the model | |
| model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy']) | |
| #train the model | |
| model.fit(x_train, y_train, batch_size=1, epochs=5) | |
| #create test dataset | |
| test_data = scaled_data[train_data_len-60:, :] | |
| #create dataset x_test, y_test | |
| x_test = [] | |
| y_test = dataset[train_data_len:, :] | |
| for i in range(60,len(test_data)): | |
| x_test.append(test_data[i-60:i, 0]) | |
| #convert data to numpy array | |
| x_test = np.array(x_test) | |
| #reshape the data | |
| x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1)) | |
| #get the models predicted price values | |
| predictions = model.predict(x_test) | |
| predictions = scaler.inverse_transform(predictions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment