Algorithms | Optimization Calculus | Object-Oriented Python
To build robust, production-grade predictive systems, a Data Scientist must understand the mathematical engine driving the models, not just the API.
This repository contains from-scratch Python/NumPy implementations of core machine learning algorithms. By bypassing high-level libraries, this project demonstrates a deep, applied understanding of loss function optimization, gradient descent calculus, matrix operations, and algorithmic complexity.
(Note: These are built using strict Object-Oriented Programming (OOP) principles to mimic standard ML library architectures).
- Linear Regression: (Gradient Descent & Normal Equation implementations)
- Logistic Regression: (Sigmoid activation and Cross-Entropy loss optimization)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::Still Under development:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- Decision Trees: (Recursive splitting via Gini Impurity and Information Gain)
- K-Nearest Neighbors (KNN): (Custom distance metrics including Euclidean and Manhattan)
- K-Means Clustering: (Centroid initialization and iterative reassignment)
To ensure accurate convergence without relying on black-box libraries, models are optimized using explicit mathematical formulations.
For instance, the Linear Regression implementation minimizes the Mean Squared Error (MSE) cost function:
Through vectorized Batch Gradient Descent, updating weights iteratively:
For Logistic Regression, the optimization relies on minimizing the Log Loss (Binary Cross-Entropy):
The models are designed with a familiar, scikit-learn-style API for seamless training and inference:
import numpy as np
from models.linear_regression import CustomLinearRegression
# 1. Initialize custom model with hyperparameters
model = CustomLinearRegression(learning_rate=0.01, iterations=1000)
# 2. Fit to training data (optimizing via gradient descent)
model.fit(X_train, y_train)
# 3. Generate predictions
predictions = model.predict(X_test)