Download the source code from here:
https://onepagecode.substack.com/
This video provides a comprehensive guide to building machine learning models for stock price prediction using Python libraries like TensorFlow and Keras. We'll explore various techniques, including Long Short-Term Memory (LSTM) networks, Artificial Neural Networks (ANNs), and Convolutional Neural Networks (CNNs), for time-series analysis. Step-by-step, we'll walk through data loading, preprocessing, feature engineering, model training, evaluation, and visualization.
The video covers:
Data acquisition and preparation
Feature engineering for time-series data
LSTM, ANN, and CNN model building for regression
Model training, evaluation, and hyperparameter tuning
Visualization of actual vs. predicted stock returns
Performance metrics analysis for model selection
00:00:00 Colab check, Drive mount, directory change
00:00:47 Activate interactive shell and autoreload, import helper module.
00:01:10 Import necessary libraries and modules
00:02:16 Load stock and index data from CSV files
00:03:15 Plot closing prices of Apple (AAPL) and S&P 500 (SPY)
00:04:51 Plot returns of Apple (AAPL) and S&P 500 (SPY).
00:05:55 Histogram of Apple (AAPL) returns with limited x-axis range
00:06:20 Histogram of S&P 500 (SPY) returns with limited x-axis range
00:06:40 Comparison of adjusted close prices between Apple (AAPL) and S&P 500 (SPY)
00:07:07 Data preprocessing and feature engineering.
00:08:38 Invokes data preprocessing function.
00:09:10 Generates statistical summary of data
00:09:45 Visualizes data correlation heatmap
00:10:19 Splits data for time-series analysis.
00:11:32 Applies rolling window normalization
00:12:57 Normalize and split data for training.
00:14:03 Normalize and prepare test dataset
00:15:39 Plot actual vs. predicted stock returns
00:16:38 Split and normalize training data
00:17:38 Split and normalize test data
00:18:03 Train model, display feature importances
00:19:03 Compute, display mutual information scores
00:20:01 Define and summarize LSTM neural network
00:21:49 Compile, train LSTM model; plot training history
00:23:09 Predict stock prices with LSTM model
00:23:47 Predict stock prices on test data
00:24:07 Invert scaling for actual and predicted values
00:24:41 Save LSTM model and training history
00:25:05 Plot actual vs. predicted validation returns
00:25:39 Plot actual vs. predicted test returns
00:26:12 Calculate, display validation performance metrics.
00:28:06 Calculate, display test performance metrics
00:29:39 Plot histogram of validation residuals
00:29:58 Plot residuals against predicted values
00:30:28 Define and summarize dense neural network
00:31:13 Compile, train ANN model; plot training history
00:32:15 Predict stock prices with ANN model.
00:32:49 Predict stock prices on test data with ANN
00:33:10 Save ANN model and training history
00:33:29 Invert scaling for actual and predicted ANN values
00:34:13 Plot actual vs. predicted ANN validation returns
00:34:41 Plot of actual and predicted returns using ANN
00:35:09 Short evaluation metrics for the validation set
00:37:11 Evaluation metrics for the test set
00:38:44 Histogram of residuals for the validation set
00:39:09 Residuals vs. predicted values plot
00:39:36 CNN model for regression with dropout
00:41:49 Training and validation loss plotted
00:42:57 CNN model's training and validation predictions are made.
00:43:51 CNN model's test predictions are made
00:44:09 Model and history are saved using the helper class.
00:44:48 Data is transformed back to original scale
00:45:31 Few words: Plotting actual vs. predicted returns.
00:45:50 Plotting actual vs. predicted returns for test data
00:46:19 Calculating evaluation metrics for the validation set.
00:47:59 Calculating evaluation metrics for the test set
00:49:31 Displaying the histogram of residuals for the validation set predictions
00:49:50 Scatter plot of residuals against predicted values for the validation set
00:50:21 Loads a saved model named model_name2 using a helper function
00:50:39 Saves, loads Keras model, predicts test data
00:52:57 Predicts stock prices for holdout data
00:54:06 Print Done