100 beginner machine learning projects with runnable Python code, tests and honest case studies. By Networkers Home, Bangalore.
This educational project demonstrates a simple approach to short-horizon stock-price forecasting using synthetic adjusted-price time series. It emphasises chronological evaluation (walk-forward), compares a lag-feature regression model to two naive baselines (last-price and simple-return extrapolation), and reports mean absolute error (MAE) and R2 at multiple horizons.
This is not investment advice, trading execution code, or a backtest using licensed market data. Instead the dataset is a small synthetic stand-in that mimics key statistical features of equity returns for educational purposes only.
The data are synthetic adjusted prices generated inside the code with a geometric Brownian motion (GBM) process. From that price series we build lag features (last price, prior returns), short moving averages and target prices at horizons 1, 5 and 10 days. For reproducibility the generator uses a fixed random seed passed to the run() function.
Run the project file with Python 3.11+. It prints a JSON object with the metrics. Example:
python project.py
You can also import run from project and call run(seed=42) programmatically.
This repository includes pytest tests. From the project root run:
pytest -q
The tests check presence of expected keys, conservative metric floors, valid ranges and determinism of the main metric when called with the same seed.
Measured by running python project.py (seed 42) on 2026-10-23; the tests in test_project.py assert the floor.
| Metric | Value |
|---|---|
| mae_horizon_1 | 1.0004 |
| r2_horizon_1 | 0.9821 |
| baseline_last_r2_h1 | 0.9875 |
| baseline_last_mae_h1 | 1.2272 |
| baseline_return_r2_h1 | 0.9886 |
| baseline_return_mae_h1 | 1.1786 |
| mae_horizon_5 | 2.3329 |
| r2_horizon_5 | 0.8940 |
| baseline_last_r2_h5 | 0.9636 |
| baseline_last_mae_h5 | 2.0488 |
| baseline_return_r2_h5 | 0.9411 |
| baseline_return_mae_h5 | 2.6039 |
| mae_horizon_10 | 3.2970 |
| r2_horizon_10 | 0.8097 |
| baseline_last_r2_h10 | 0.9389 |
| baseline_last_mae_h10 | 2.7587 |
| baseline_return_r2_h10 | 0.8342 |
| baseline_return_mae_h10 | 4.5031 |
| avg_transaction_cost_per_prediction | 0.0500 |
| note | Synthetic GBM used. Model: Ridge regression. Chronological walk-forward evaluation. Educational only. |
Full case study, build steps and evaluation checks: Stock price predictor on networkershome.com
Built by Networkers Home · Learn the skills in the AI Engineer Course · Part of 100 AI projects with code