Create Your First Project
Start adding your projects to your portfolio. Click on "Manage Projects" to get started
Predicting Stock Prices with LSTM Neural Networks
Project type
Machine Learning
Date
May 2023
Notebook Link
Presentation Link
This study encompasses a set of 10 stocks from various industry sectors, including technology, finance, and manufacturing, to examine the generalizability of the LSTM model across different stocks and market conditions. Python was used for this project using the Keras library
The stocks selected for this study are listed below:
stock_files = ["AAPL.csv", "AMZN.csv", "FB.csv", "GE.csv", "GOOGL.csv", "GS.csv", "IBM.csv", "JPM.csv", "MSFT.csv", "TSLA.csv"]
Data Training Procedure:
The data for each stock was loaded and processed using the load_and_preprocess_data function. This involved normalizing the data using the MinMaxScaler, and then splitting it into training and testing sets, with 80% of the data allocated to training and 20% allocated to testing.
Then, the data was prepared for input into the LSTM model by creating input-output pairs using the create_dataset function. This involved selecting a time_steps value (in this case, 60) and generating sequences of data points that span this time frame. Each input sequence was then paired with a corresponding output value, which is the opening price of the stock immediately following the input sequence.
The LSTM model architecture was defined using the Keras library. This model consists of three LSTM layers, each with 50 neurons, interspersed with Dropout layers to prevent overfitting. The final Dense layer has one neuron, which outputs the predicted opening price. The model is compiled with the Adam optimizer, a learning rate of 0.001, and the mean squared error as the loss function.
With the model architecture defined, the LSTM model was trained using the training data (X_train and y_train). The number of training epochs (100) and the batch size (32) are specified to control the learning process.The model's training progress was monitored, and adjustments to the architecture, learning rate, or other hyperparameters can be made as needed to improve performance.
After training the LSTM model on the AAPL stock, the same process was applied to the remaining nine stocks. This ensures that the model is capable of generalizing across various stocks and industry sectors. In order to ensure the reliability of this model, cross-validation is utilized to evaluate the model's performance and to try and prevent overfitting.

