• Version: 20261019
  • Source Code Copyright: Unknown
  • Redistribution Restriction: This source code is integrated by LEADERG INC. Please use it privately. Please DO NOT distribute it to internet.

Console/terminal pipeline for multi-horizon stock-price regression with Random Forests (scikit-learn), supporting Windows 11, Ubuntu Linux 24.04 and macOS 14+ (Apple Silicon). Step 04 builds one training CSV per prediction horizon from the raw daily table (25 features = 5 consecutive days × 5 columns; targets close after 1..5 days; 10% validation split); step 05 trains one deterministic Random Forest per horizon; step 06 validates each model on its held-out split. CPU only: scikit-learn has no GPU backend (no CUDA, no Apple GPU), and the full pipeline takes about a minute on the CPU.

 

Data-Regression-Forest-Stock-inference-Jupyter.png

 

[Folder Structure]

  • CLAUDE.md / AGENTS.md: Program specification (identical content).
  • CHANGELOG.md: Change log.
  • copyright.txt: Copyright notice.
  • Data-Regression-Forest-Stock-Python.html: This document (usage page).
  • Classification_and_Regression_by_RandomForest.pdf: Reference paper.
  • data/stock/: stock-origin.csv (raw table) + stock-25to5-{N}[-validation].csv (written by step 04).
  • model/stock/: stock-25to5-{N}.sav (models), .pkl (scalers), train_day{N}.png, validation_day{N}.png.
  • tool/tools.py: Shared helpers.
  • src/: Source code and launcher scripts.
  • venv/: Python virtual environment, created by 02_venv_create_windows/linux/mac.

[Prerequisites]

  • Python 3.14, installed by 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh (Windows: winget; Ubuntu: apt, or the deadsnakes PPA when the Ubuntu archive has no python3.14; macOS: Homebrew).
  • 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh create venv/ with Python 3.14 and install pandas, numpy, scikit-learn and matplotlib from src/requirements.txt (same packages on every OS).
  • GPU: none. CPU only on every OS, because scikit-learn has no GPU backend; no NVIDIA driver or CUDA is needed.

[Launcher Scripts]

1. 01_python_install_windows.bat / 01_python_install_linux.sh / 01_python_install_mac.sh

Install Python 3.14 (winget / apt or deadsnakes PPA, needs sudo / Homebrew). Skips the install when Python 3.14 is already present. On Windows, open a new terminal afterwards.

 

2. 02_venv_create_windows.bat / 02_venv_create_linux.sh / 02_venv_create_mac.sh

Delete the old venv/, create a fresh one with Python 3.14, install src/requirements.txt. Aborts loudly if pip fails.

 

3. 03_venv_activate.bat / 03_venv_activate.sh

Activate the venv. On Linux/macOS, source it: source src/03_venv_activate.sh (bash or zsh). If the project folder was renamed after the venv was created, re-create the venv with 02_venv_create_windows/linux/mac first; the other launchers do not need activation.

 

4. 04_prepare.bat / 04_prepare.sh

Build the per-horizon training/validation CSVs from stock-origin.csv.

 

5. 05_train.bat / 05_train.sh

Train one Random Forest per horizon; save models/scalers/plots.

 

6. 06_inference.bat / 06_inference.sh

Validate each model on its held-out split; save plots.

 

7. 99_venv_clean.bat / 99_venv_clean.sh

Delete the venv/ folder.

 

8. 99_venv_deactivate.bat / 99_venv_deactivate.sh

Deactivate the venv in the current shell. On Linux/macOS, source it: source src/99_venv_deactivate.sh (bash or zsh).

[Python Entry Points]

src/prepare.py

--dataset stock --input data/stock/stock-origin.csv --augmentation 5 --outputs 5 --validation-proportion 0.1. Drops zero-volume rows, stacks 5 consecutive days into 25 feature columns, appends the target, splits off the last 10%.

 

src/train.py

--dataset stock --augmentation 5 --outputs 5 --estimators 300 [--show]. Per horizon: MinMaxScaler + RandomForestRegressor(random_state=0); saves .sav/.pkl/train_day{N}.png.

 

src/inference.py

--dataset stock --augmentation 5 --outputs 5 [--show]. Per horizon: predicts on the validation CSV; saves validation_day{N}.png.

 

All three run on the CPU (scikit-learn has no GPU backend); there is no --device option.

[Quick Start]

Windows 11

src\01_python_install_windows.bat

REM open a new terminal

src\02_venv_create_windows.bat

src\04_prepare.bat

src\05_train.bat

src\06_inference.bat

 

Ubuntu 24.04

bash src/01_python_install_linux.sh

bash src/02_venv_create_linux.sh

bash src/04_prepare.sh

bash src/05_train.sh

bash src/06_inference.sh

 

macOS 14+ (Apple Silicon)

bash src/01_python_install_mac.sh

bash src/02_venv_create_mac.sh

bash src/04_prepare.sh

bash src/05_train.sh

bash src/06_inference.sh

Run the steps in order on a new environment (pickles are not portable across scikit-learn versions). The shipped .sav / .pkl files were written by scikit-learn 1.9.0; a newer scikit-learn still loads them but prints an InconsistentVersionWarning until step 05 rewrites them. The full pipeline takes about a minute on CPU.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.