# insane-pro/ml-from-scratch architecture

> Architecture diagram of the GitHub repository insane-pro/ml-from-scratch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/insane-pro/ml-from-scratch
- Repository: https://github.com/insane-pro/ml-from-scratch

## Overview

This repository is a from-scratch linear-regression library, with utilities for preparing data and custom error reporting. Its main workflow is to prepare features, fit an OLS, Ridge, or Lasso model, and use the model’s shared prediction and loss-tracking behavior. The README also documents vectorized gradient descent and benchmarking against scikit-learn; the benchmark script is not mapped as runtime product architecture. The graph reflects documented capabilities and visible imports; unsampled model and logger internals limit further call-level detail.

Main entry points: [`src/pipeline.py`](https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py) (Data ingestion), [`src/base.py`](https://github.com/insane-pro/ml-from-scratch/blob/main/src/base.py) (Model base), [`src/linear.py`](https://github.com/insane-pro/ml-from-scratch/blob/main/src/linear.py) (OLS regression), [`src/regularization.py`](https://github.com/insane-pro/ml-from-scratch/blob/main/src/regularization.py) (Ridge regression)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_models["Regression models"]
  node_base["Model base<br/>[base.py]"]
  node_ols["OLS regression<br/>[linear.py]"]
  node_gradient["Gradient descent<br/>[linear.py]"]
  node_ridge["Ridge regression<br/>[regularization.py]"]
  node_lasso["Lasso regression<br/>[regularization.py]"]
end

subgraph group_preparation["Data preparation"]
  node_data["Data ingestion<br/>[pipeline.py]"]
  node_features["Polynomial features<br/>[pipeline.py]"]
  node_scaling["Split and scale<br/>[pipeline.py]"]
end

subgraph group_operations["Error reporting"]
  node_logger["Logging<br/>[logger.py]"]
  node_exception["Custom exception<br/>[exception.py]"]
end

node_user(("Library user"))
node_diabetes[("Diabetes dataset")]
node_sklearn_poly["PolynomialFeatures"]

node_user -->|"prepares data"| node_data
node_user -->|"fits model"| node_ols
node_user -->|"fits model"| node_gradient
node_user -->|"fits model"| node_ridge
node_user -->|"fits model"| node_lasso
node_ols -->|"inherits"| node_base
node_ridge -->|"inherits"| node_base
node_lasso -->|"inherits"| node_base
node_data -->|"loads"| node_diabetes
node_data -->|"expands features"| node_features
node_features -->|"uses"| node_sklearn_poly
node_exception -->|"imports logging"| node_logger

click node_base "https://github.com/insane-pro/ml-from-scratch/blob/main/src/base.py"
click node_ols "https://github.com/insane-pro/ml-from-scratch/blob/main/src/linear.py"
click node_gradient "https://github.com/insane-pro/ml-from-scratch/blob/main/src/linear.py"
click node_ridge "https://github.com/insane-pro/ml-from-scratch/blob/main/src/regularization.py"
click node_lasso "https://github.com/insane-pro/ml-from-scratch/blob/main/src/regularization.py"
click node_data "https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py"
click node_features "https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py"
click node_scaling "https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py"
click node_logger "https://github.com/insane-pro/ml-from-scratch/blob/main/src/logger.py"
click node_exception "https://github.com/insane-pro/ml-from-scratch/blob/main/src/exception.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_base,node_ols,node_gradient,node_ridge,node_lasso,node_user toneBlue
class node_data,node_features,node_scaling,node_diabetes toneAmber
class node_logger,node_exception toneMint
class node_sklearn_poly toneIndigo
```

## Components

### Regression models

- [Model base](https://github.com/insane-pro/ml-from-scratch/blob/main/src/base.py): `src/base.py`
- [OLS regression](https://github.com/insane-pro/ml-from-scratch/blob/main/src/linear.py): `src/linear.py`
- [Gradient descent](https://github.com/insane-pro/ml-from-scratch/blob/main/src/linear.py): `src/linear.py`
- [Ridge regression](https://github.com/insane-pro/ml-from-scratch/blob/main/src/regularization.py): `src/regularization.py`
- [Lasso regression](https://github.com/insane-pro/ml-from-scratch/blob/main/src/regularization.py): `src/regularization.py`

### Data preparation

- [Data ingestion](https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py): `src/pipeline.py`
- [Polynomial features](https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py): `src/pipeline.py`
- [Split and scale](https://github.com/insane-pro/ml-from-scratch/blob/main/src/pipeline.py): `src/pipeline.py`

### Error reporting

- [Logging](https://github.com/insane-pro/ml-from-scratch/blob/main/src/logger.py): `src/logger.py`
- [Custom exception](https://github.com/insane-pro/ml-from-scratch/blob/main/src/exception.py): `src/exception.py`

### Other components

- **Library user**
- **Diabetes dataset**
- **PolynomialFeatures**

## Connections

- Library user → Data ingestion: prepares data (evidence: `README.md`)
- Library user → OLS regression: fits model (evidence: `README.md`)
- Library user → Gradient descent: fits model (evidence: `README.md`)
- Library user → Ridge regression: fits model (evidence: `README.md`)
- Library user → Lasso regression: fits model (evidence: `README.md`)
- OLS regression → Model base: inherits (evidence: `src/linear.py`)
- Ridge regression → Model base: inherits (evidence: `src/regularization.py`)
- Lasso regression → Model base: inherits (evidence: `src/regularization.py`)
- Data ingestion → Diabetes dataset: loads (evidence: `src/pipeline.py`)
- Data ingestion → Polynomial features: expands features (evidence: `src/pipeline.py`)
- Polynomial features → PolynomialFeatures: uses (evidence: `src/pipeline.py`)
- Custom exception → Logging: imports logging (evidence: `src/exception.py`)
