How geminusf/ml_final_project works
Purpose and execution
This is a Python 3.12 research repository implementing ensemble-learning and unsupervised algorithms primarily with NumPy, then evaluating them through deterministic experiment suites. The main operational entry point is src/experiments/run_all.py; it runs full or quick profiles, writes evidence to results/, and produces plots in figures/. Data acquisition/verification begins at download_data.sh.
Core supervised learners
The custom weighted CART tree is the shared weak/base learner: src/trees/decision_tree.py. AdaBoost implements multiclass SAMME, staged predictions, early stopping, and SAMME.R support in src/boosting/adaboost.py, with a compatibility/export module at src/trees/adaboost.py. Random Forest owns bootstrap sampling, feature subsampling, OOB accounting, aligned probabilities, and deterministic parallel/sequential execution: src/bagging/random_forest.py, src/trees/random_forest.py.
Gradient Boosting is a separate bonus binary-classification implementation in src/boosting/gradient_boosting.py.
Data and leakage boundary
Dataset registration, source loading, deterministic Covertype subset selection, and provenance checks are centralized in src/experiments/datasets.py; the verified snapshot is data/dataset_audit.json. Training/test and fold boundaries are enforced before transforms. Leakage-safe numeric/categorical preprocessing, training-only fitting of encoders/scalers, and fold-local oversampling live in src/utils/preprocessing.py. Raw downloaded data is intentionally external/Git-ignored.
Experiment orchestration
src/experiments/config.py defines experiment profiles and parameters; src/experiments/runner.py executes the seven experiment families and bonus studies. src/experiments/run_all.py coordinates datasets, profiles, artifact generation, and final manifests. The runner drives baseline comparisons, boosting/RF scaling, cross-validated head-to-head tests, label-noise replicates, bootstrap bias-variance analysis, and unsupervised evaluation.
Progress and runtime state are separated from numerical computation in src/experiments/progress.py, preserving deterministic seeds and artifacts.
Metrics and artifact contract
Classification and bias-variance evaluation are centralized in src/metrics/evaluation.py. Result artifacts are stable CSV, JSON, and NPZ files grouped by experiment under results/; aggregate reproducibility/runtime metadata is written to results/manifest.json and results/runtime.json. These files are the boundary between compute stages and report/figure consumers.
Unsupervised pipeline
From-scratch centered PCA, K-Means, and DBSCAN reside in src/unsupervised/pca.py, src/unsupervised/kmeans.py, and src/unsupervised/dbscan.py. Experiment execution produces PCA variance/scree outputs, K-Means restart/elbow outputs, DBSCAN k-distance and clustering metrics, and visualization inputs under results/07_unsupervised/.
Runtime and external dependencies
The material runtime is local Python/NumPy with pinned dependencies in requirements.txt. scikit-learn is limited to permitted dataset loaders/reference estimators and utilities such as ARI/t-SNE. Adult data may come from UCI/OpenML and Covertype from UCI/scikit-learn cache; download_data.sh supports local fallbacks. Random Forest may use spawned multiprocessing workers, with deterministic sequential fallback when process pipes are unavailable.
Main entry points: runner.py Experiment runner · manifest.json Results artifacts · decision_tree.py Weighted CART · datasets.py Dataset registry
Components 21
Data boundary
Verified data and leakage-safe preparation.
- Data acquisition · Downloads data or uses local fallbacks.
download_data.sh - Dataset audit · Stores dataset provenance verification.
data/dataset_audit.json - Dataset registry · Registers sources and selects deterministic subsets.
src/experiments/datasets.py - Leakage-safe preprocessing · Fits transforms and oversampling only on training folds.
src/utils/preprocessing.py
Supervised learners
Custom NumPy classification implementations.
- Weighted CART · Shared weighted decision-tree weak learner.
src/trees/decision_tree.py - AdaBoost SAMME · Supports multiclass staging, early stopping, and SAMME.R.
src/boosting/adaboost.py - AdaBoost compatibility export
src/trees/adaboost.py - Random Forest · Bootstraps, subsamples features, tracks OOB, and supports deterministic parallelism.
src/bagging/random_forest.py - RF compatibility export
src/trees/random_forest.py - Gradient Boosting · Separate binary-classification implementation.
src/boosting/gradient_boosting.py
Experiment runtime
Deterministic experiment execution and artifacts.
- Experiment profiles · Defines full and quick profiles and parameters.
src/experiments/config.py - Run all · Coordinates datasets, profiles, artifacts, and manifests.
src/experiments/run_all.py - Experiment runner · Executes seven experiment families and bonus studies.
src/experiments/runner.py - Progress state · Separates progress reporting from deterministic numerical work.
src/experiments/progress.py - Evaluation metrics · Centralizes classification and bias-variance evaluation.
src/metrics/evaluation.py - Results artifacts · Stable CSV, JSON, and NPZ outputs by experiment.
results/manifest.json - Run manifests · Aggregate manifest and runtime metadata.
results/runtime.json - Figures
figures/07_unsupervised
Unsupervised pipeline
From-scratch clustering and dimensionality reduction.
- Centered PCA
src/unsupervised/pca.py - K-Means
src/unsupervised/kmeans.py - DBSCAN
src/unsupervised/dbscan.py
Connections 23
- Data acquisition → Dataset registry: acquires sources
- Dataset audit → Dataset registry: verifies provenance
- Dataset registry → Run all: loads registered data
- Experiment profiles → Run all: selects profile
- Run all → Experiment runner: launches suites
- Experiment runner → Leakage-safe preprocessing: creates train/fold transforms
- Leakage-safe preprocessing → Weighted CART: prepared training data
- Weighted CART → AdaBoost SAMME: weak learner
- Weighted CART → Random Forest: tree estimator
- AdaBoost compatibility export → AdaBoost SAMME: exports
- RF compatibility export → Random Forest: exports
- Experiment runner → Gradient Boosting: runs bonus study
- Experiment runner → AdaBoost SAMME: runs scaling and comparisons
- Experiment runner → Random Forest: runs scaling and comparisons
- Experiment runner → Centered PCA: runs unsupervised evaluation
- Experiment runner → K-Means: runs restarts and elbow
- Experiment runner → DBSCAN: runs k-distance and clustering
- Experiment runner → Evaluation metrics: evaluates predictions
- Experiment runner → Progress state: reports runtime state
- Evaluation metrics → Results artifacts: writes experiment evidence
- Experiment runner → Results artifacts: writes outputs
- Results artifacts → Run manifests: aggregates metadata
- Results artifacts → Figures: supplies plot inputs