↓Skip to main content

Machine Learning Algorithms from Scratch

MSDS Coursework | Batangas State University | 2025–2026
GitHub Repository →


Overview

A comprehensive educational and engineering repository implementing five core classical machine learning algorithms entirely from first principles using pure NumPy — omitting high-level estimators like Scikit-learn to focus on mathematical rigor, vectorization, and underlying gradient mechanics.

Each algorithm is accompanied by step-by-step formula derivations, markdown explanations, loss curves, and decision boundary plots.

View Code on GitHub

Implementations & Benchmarks

AlgorithmDatasetMathematical CoreBenchmark Result
Linear RegressionTV Marketing (200 samples)Ordinary Least Squares, Closed-form Normal Eq. & Batch Gradient DescentPearson’s $r = 0.782$
Logistic RegressionPima Indians Diabetes (768 samples)Sigmoid activation, Binary Cross-Entropy, Vectorized Gradient UpdatesSigmoid probability curves
Decision TreeIris Dataset (150 samples)Information Gain, Shannon Entropy, Recursive Binary SplittingTrain: 78.57% / Test: 71.05%
K-Nearest NeighborsPima Indians Diabetes (768 samples)Euclidean metric vectorization, Majority VotingOptimal $k = 5$, Accuracy: 72.73%
Naive BayesIris Dataset (150 samples)Gaussian Likelihood, Bayes’ Theorem, Log-sum-exp stabilizationAccuracy: 90.00%

Methodological Principles

  • Zero Black Boxes: Scikit-learn is restricted strictly to cross-validation dataset splitting and metric calculation; all core optimization loops and probability estimations are written in pure NumPy.
  • Vectorized Formulations: Eliminated nested Python loops in favor of vectorized matrix operations, ensuring efficient vectorized execution.
  • Complete Documentation: Includes comprehensive technical derivations in both Markdown and exported PDFs.

Tech Stack: Python · NumPy · Pandas · Matplotlib · Seaborn · Google Colab · LaTeX