Skip to main content

A transparent, 'Glass Box' Machine Learning library designed for education.

Project description

MLMechanica

Python Version License Status

Machine Learning, Unveiled.

mlmechanica is a custom Machine Learning library built from scratch in Python. Unlike traditional libraries that treat models as "black boxes," MLMechanica is designed to be a "Glass Box"---offering complete transparency into the mathematical operations, internal states, and iterative steps of every algorithm.

It is strictly educational, optimized for clarity and understanding rather than production speed.


🚀 Key Features

  • Transparency First: Enable the calculation=True flag to see every matrix multiplication, gradient update, and intermediate derivation logged to your console in real-time.
  • Pure Python & NumPy: Implementations rely solely on NumPy for linear algebra, avoiding high-level abstractions to show exactly how the math works.
  • Self-Documenting Models: Every class includes a model_analysis() method that returns the rigorous mathematical derivation and theory behind that specific algorithm.
  • Instant Demos: Built-in static demo() methods allow you to run smoke tests and visualize model performance instantly without writing setup code.

📦 Installation

From Source

You can clone the repository directly from GitHub:

git clone https://github.com/Sarbik-Mal/mlmechanica.git
cd mlmechanica
pip install .

(Note: PyPI installation coming soon via pip install mlmechanica)


⚡ Quick Start

1. Run a built-in Demo

Want to see Lasso Regression in action immediately? Every model comes with a static demo that generates synthetic data, trains the model, and evaluates it.

from mlmechanica.regression.linear import LassoRegression


LassoRegression.demo()

2. Custom Usage with "Calculation Mode"

See the internal math (Gradient Descent, Matrix Inversion, etc.) by setting calculation=True.

import numpy as np
from mlmechanica.regression.linear import MultipleLinearRegression

X = np.array([[1, 2], [2, 3], [3, 4], [4, 5]])
y = np.array([2, 3, 4, 5])

model = MultipleLinearRegression(calculation=True)

model.fit(X, y)

pred = model.predict(np.array([[5, 6]]))
print(f"Prediction: {pred}")

📚 Supported Models

Currently, the library focuses on linear regression techniques:

Module Class Description
Simple Linear SimpleLinearRegression Univariate regression using closed-form OLS derivation.
Multiple Linear MultipleLinearRegression Multivariate regression using the Normal Equation (Vectorized).
Lasso LassoRegression L1 Regularization using Coordinate Descent and Soft Thresholding.
Ridge RidgeRegression L2 Regularization offering multiple solvers: lsqr, svd, cholesky, and mbsag (Stochastic Avg Gradient).

🧠 Model Analysis

Retrieve the mathematical derivation directly from any model:

from mlmechanica.regression.linear import SimpleLinearRegression

model = SimpleLinearRegression()

print(model.model_analysis('derivation'))

🤝 Contributing

Contributions are welcome! This is an educational project, so clarity and readability are prioritized.

  1. Fork the Project\
  2. Create a Feature Branch (git checkout -b feature/NewAlgorithm)\
  3. Commit Changes (git commit -m 'Add DecisionTree implementation')\
  4. Push to Branch (git push origin feature/NewAlgorithm)\
  5. Open a Pull Request

📄 License

Distributed under the MIT License. See LICENSE for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mlmechanica-0.1.0.tar.gz (74.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mlmechanica-0.1.0-py3-none-any.whl (78.1 kB view details)

Uploaded Python 3

File details

Details for the file mlmechanica-0.1.0.tar.gz.

File metadata

  • Download URL: mlmechanica-0.1.0.tar.gz
  • Upload date:
  • Size: 74.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for mlmechanica-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d1d0365246ce340abaf756c8236884d6f65bc8d3932e5e3a64635e65916766a3
MD5 bc929610d7a5fabf23b590f2fd5e6cf5
BLAKE2b-256 6dc57091186bef049043201b86ba079962458725b3a4a2e5ec527b6a8f79bcac

See more details on using hashes here.

File details

Details for the file mlmechanica-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mlmechanica-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 78.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for mlmechanica-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71062b58cad325b0b524eeadc58f96272127fda38f6abe3bb49225b555006769
MD5 ad371b9a694dbae010b600e497d8f79f
BLAKE2b-256 fe260367f4b492efd82a36f2da5cbcf4186b48d3062e2957bc06e1a62bc9a4a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page