A machine-learning project implementing:
- Multiclass (softmax) logistic regression trained with gradient descent
- Multiclass logistic regression (K−1 parameterization) trained with Newton / IRLS
- Gaussian Naive Bayes (with variance smoothing) + sampling
- Bernoulli Naive Bayes (with Lidstone smoothing) + sampling
Benchmarked on:
- Iris (toy multiclass dataset)
- MNIST (OpenML) (handwritten digits)
python -m venv .venv
source .venv/bin/activatepip install -r requirements.txtOptional dev dependencies (tests):
pip install -r requirements-dev.txtAll scripts are designed to run from the repo root.
Gradient Descent (no bias):
python scripts/iris_gd.pyGradient Descent (with bias via intercept feature):
python scripts/iris_gd_bias.pyIRLS/Newton vs GD (no bias):
python scripts/iris_irls_vs_gd.pyIRLS/Newton vs GD (with bias via intercept feature):
python scripts/iris_irls_vs_gd_bias.pyScikit-learn baseline comparisons:
python scripts/iris_sklearn_baseline.pyGaussian NB baseline (alpha=1e-7):
python scripts/mnist_gnb_baseline.pyGaussian NB smoothing sweep:
python scripts/mnist_gnb_sweep.pyGaussian NB digit generation (uses alpha_best=0.1 by default):
python scripts/mnist_gnb_generate.pyBernoulli NB eval (alpha=1e-8):
python scripts/mnist_bnb_eval.pyBernoulli NB digit generation:
python scripts/mnist_bnb_generate.pyNote on MNIST download: fetch_openml caches downloads under openml_cache/ (ignored by git). The first MNIST run can take a while depending on network speed.
- Logistic regression loss uses
scipy.special.log_softmaxto avoid overflow/underflow. - Naive Bayes prediction is computed in log-space and normalized with
scipy.special.logsumexp. - Gaussian NB variance smoothing improves stability on high-dimensional MNIST features.
Run sanity checks:
pytest -qMIT (see LICENSE).



