← Back to Portfolio
Case Study — Deep Learning / Time Series

LSTM Stock
Price Predictor

A two-layer LSTM that learns from historical closing prices and predicts the next day's close, with a Streamlit app for interactive use and a script for repeatable runs. A learning project, written to be read and extended.

Python TensorFlow / Keras scikit-learn yfinance Streamlit Matplotlib ▶ Personal Project ยท 2025
2 LSTM Layers
60 Day Default Window
80/20 Train / Test Split
2 Interfaces
01 — The Goal

Learning Time-Series Deep Learning

Prices are a sequence, so the model needs windows of history, not isolated rows.

🧹

Shape the data

Closing prices are scaled to 0 to 1 and cut into overlapping windows, giving the 3-dimensional input an LSTM expects.

🧠

Train a sequence model

A stacked LSTM with dropout learns from the windows and saves its best weights to disk.

💻

Make it usable

The same code runs from a Streamlit app with sliders and from a plain script, so results can be repeated.

02 — Pipeline

How the Model Is Built

Each stage is its own small module in src/, shared by the app and the script.

Data
yfinance download Close price only
↓ scale and window
Preprocess
MinMaxScaler 0 to 1 Windows of N days
↓ train and test
Model
LSTM 50 + Dropout 0.2 LSTM 50 + Dropout 0.2 Dense 25 to Dense 1
↓ Adam, mean squared error
Training
ModelCheckpoint: keep best weights
↓ predict and inverse scale
Output
Actual vs predicted chart Next-day closing price
03 — Features

What It Does

Everything the README describes, and what the code does.

📊

Interactive app

Choose a ticker, a date preset or custom range, the lookback window (30 to 100 days) and the number of epochs, then train and predict.

📈

Charts

The downloaded price history and an actual versus predicted plot for the test period.

📅

Next-day prediction

The last window of prices is scaled, passed through the model and converted back to a dollar value.

💾

Saved weights

The best model weights are written to model/lstm_model.h5 for reuse.

🔧

Script mode

main.py trains, evaluates and prints the next-day price without the UI.

⚙️

Adjustable

Ticker, dates, window and epochs are parameters, and the architecture lives in one file.

04 — Technology

Technology Choices

A standard Python data-science stack.

LayerTechnologyWhy
Data yfinance Free historical prices from Yahoo Finance.
Model TensorFlow / Keras A Sequential LSTM is short to define and easy to read.
Scaling scikit-learn MinMaxScaler LSTMs train better on inputs scaled to a small range, and the scaler converts predictions back.
Interface Streamlit A working UI with sliders in a few lines of Python.
Plots Matplotlib Actual versus predicted charts.
05 — Decisions

Calls That Mattered

Small choices that keep the project understandable.

01

One code path for the app and the script

Data loading, model building, training and prediction live in src/, so the Streamlit app and main.py cannot drift apart.

02

Dropout between LSTM layers

Dropout of 0.2 after each LSTM layer reduces overfitting to the training history.

03

Keep the best checkpoint

Training saves only the best weights by training loss, so the saved model is not just the last epoch.

04

Predict with the training window length

The predictor reshapes its input to whatever window the model was trained with, so changing the lookback slider does not break next-day prediction.

06 — Hard Parts

What Needed Care

The practical details of sequence models.

📐 Tensor shapes

An LSTM needs input shaped as samples, time steps and features. Getting windows, reshaping and inverse scaling consistent took care at every stage.

✓ Explicit reshape at each step

🔄 Window mismatch

If the lookback slider differs between training and prediction, the shapes disagree. The predictor reshapes dynamically to the window length in use.

✓ Dynamic reshape

👁️ Making results readable

Raw scaled numbers mean little. Inverse scaling plus an actual versus predicted chart makes the model's behaviour visible.

✓ Inverse transform and plots
07 — Outcomes

What This Demonstrates

What the project shows.

2 Interfaces A Streamlit app and a script sharing the same modules.
5 Modules Data, model, training, prediction and plotting, each in its own file.
1 Saved model Weights stored in the repo so prediction can run without retraining.
08 — Limits

Honest Limits and What I Would Change

Stock prices are hard to predict, and this project does not claim otherwise.

⚠️

Not trading advice

This is an educational model. A model that tracks yesterday's price closely can look accurate while adding no real predictive value.

🔧

Evaluation I would add

Fit the scaler on the training split only, use walk-forward validation, report RMSE and MAE, and compare against a naive "tomorrow equals today" baseline.

📐

Extensions

Add features such as volume and indicators, try multi-step forecasts, and track experiments.

Available for work

Want to build something
like this together?

I'm open to full-time roles and project work in AI engineering, full-stack development, and backend systems.