# eriklindernoren/ml-from-scratch architecture

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

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

## Overview

ML From Scratch is a Python library of transparent implementations of supervised, unsupervised, deep-learning, and reinforcement-learning algorithms. The user-facing workflow is to select an algorithm, provide data (or an environment for reinforcement learning), train or run it, and obtain predictions, clusters, rules, or generated data. The graph preserves documented algorithm families and the sampled neural-network and utility layers. Several family implementations were not sampled, so their internal connections are not inferred.

Main entry points: [`mlfromscratch/utils/data_manipulation.py`](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/data_manipulation.py) (Data manipulation), [`mlfromscratch/deep_learning/loss_functions.py`](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/loss_functions.py) (Loss functions), [`mlfromscratch/supervised_learning`](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning) (Supervised algorithms), [`mlfromscratch/unsupervised_learning`](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning) (Unsupervised algorithms)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_supervised["Supervised Learning"]
  node_supervised_catalog["Supervised algorithms"]
  node_decision_tree["Decision trees<br/>[decision_tree.py]"]
  node_boosting["Boosting models"]
  node_other_supervised["Other supervised models"]
end

subgraph group_unsupervised["Unsupervised Learning"]
  node_unsupervised_catalog["Unsupervised algorithms"]
  node_association["Association mining<br/>[apriori.py]"]
  node_fp_growth["FP-growth<br/>[fp_growth.py]"]
  node_dbscan["Density clustering<br/>[dbscan.py]"]
  node_mixture["Gaussian mixtures"]
  node_genetic["Genetic algorithm"]
  node_medoids["Medoid clustering"]
  node_other_unsupervised["Other unsupervised models"]
  node_deep_models["Other deep models"]
end

subgraph group_deep["Deep Learning"]
  node_neural_network["Neural network<br/>[neural_network.py]"]
  node_layers["Network layers<br/>[layers.py]"]
  node_activations["Activations"]
  node_losses["Loss functions<br/>[loss_functions.py]"]
  node_optimizers["Optimizers<br/>[optimizers.py]"]
end

subgraph group_reinforcement["Reinforcement Learning"]
  node_dqn["Deep Q-network<br/>[deep_q_network.py]"]
end

subgraph group_shared["Shared Utilities"]
  node_data_helpers["Data manipulation"]
  node_data_operations["Data operations<br/>[data_operation.py]"]
  node_plotting["Plotting helpers<br/>[misc.py]"]
end

node_user(("Library user"))
node_training_data["Training data"]
node_results["Model results"]
node_environment["Gym environment"]

node_user -->|"selects model"| node_supervised_catalog
node_user -->|"selects model"| node_unsupervised_catalog
node_user -->|"trains network"| node_neural_network
node_user -->|"trains agent"| node_dqn
node_training_data -.->|"provides examples"| node_supervised_catalog
node_training_data -.->|"provides examples"| node_unsupervised_catalog
node_supervised_catalog -.->|"produces predictions"| node_results
node_unsupervised_catalog -.->|"produces patterns"| node_results
node_neural_network -.->|"produces predictions"| node_results
node_decision_tree -->|"calls helpers"| node_data_helpers
node_boosting -->|"uses trees"| node_decision_tree
node_boosting -->|"uses loss"| node_losses
node_association -->|"returns rules"| node_results
node_dbscan -->|"imports utilities"| node_data_helpers
node_mixture -->|"imports utilities"| node_data_helpers
node_medoids -->|"imports utilities"| node_data_helpers
node_layers -->|"imports functions"| node_activations
node_losses -->|"imports function"| node_activations
node_losses -->|"imports accuracy"| node_data_helpers
node_optimizers -->|"imports helpers"| node_data_helpers
node_dqn -->|"steps environment"| node_environment
node_data_helpers -->|"reexports operations"| node_data_operations
node_plotting -->|"computes covariance"| node_data_operations
node_plotting -->|"standardizes data"| node_data_helpers

click node_supervised_catalog "https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning"
click node_decision_tree "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/supervised_learning/decision_tree.py"
click node_boosting "https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning"
click node_other_supervised "https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning"
click node_unsupervised_catalog "https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning"
click node_association "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/apriori.py"
click node_fp_growth "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/fp_growth.py"
click node_dbscan "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/dbscan.py"
click node_mixture "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/gaussian_mixture_model.py"
click node_genetic "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/genetic_algorithm.py"
click node_medoids "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/partitioning_around_medoids.py"
click node_other_unsupervised "https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning"
click node_neural_network "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/neural_network.py"
click node_layers "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/layers.py"
click node_activations "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/activation_functions.py"
click node_losses "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/loss_functions.py"
click node_optimizers "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/optimizers.py"
click node_deep_models "https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning"
click node_dqn "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/reinforcement_learning/deep_q_network.py"
click node_data_helpers "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/data_manipulation.py"
click node_data_operations "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/data_operation.py"
click node_plotting "https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/misc.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_supervised_catalog,node_decision_tree,node_boosting,node_other_supervised,node_user toneBlue
class node_unsupervised_catalog,node_association,node_fp_growth,node_dbscan,node_mixture,node_genetic,node_medoids,node_other_unsupervised,node_deep_models toneAmber
class node_neural_network,node_layers,node_activations,node_losses,node_optimizers toneMint
class node_dqn toneRose
class node_data_helpers,node_data_operations,node_plotting,node_training_data,node_results,node_environment toneIndigo
```

## Components

### Supervised Learning

- [Supervised algorithms](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning): `mlfromscratch/supervised_learning`
- [Decision trees](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/supervised_learning/decision_tree.py): `mlfromscratch/supervised_learning/decision_tree.py`
- [Boosting models](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning): `mlfromscratch/supervised_learning`
- [Other supervised models](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/supervised_learning): `mlfromscratch/supervised_learning`

### Unsupervised Learning

- [Unsupervised algorithms](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning): `mlfromscratch/unsupervised_learning`
- [Association mining](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/apriori.py): `mlfromscratch/unsupervised_learning/apriori.py`
- [FP-growth](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/fp_growth.py): `mlfromscratch/unsupervised_learning/fp_growth.py`
- [Density clustering](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/dbscan.py): `mlfromscratch/unsupervised_learning/dbscan.py`
- [Gaussian mixtures](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/gaussian_mixture_model.py): `mlfromscratch/unsupervised_learning/gaussian_mixture_model.py`
- [Genetic algorithm](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/genetic_algorithm.py): `mlfromscratch/unsupervised_learning/genetic_algorithm.py`
- [Medoid clustering](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/unsupervised_learning/partitioning_around_medoids.py): `mlfromscratch/unsupervised_learning/partitioning_around_medoids.py`
- [Other unsupervised models](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning): `mlfromscratch/unsupervised_learning`
- [Other deep models](https://github.com/eriklindernoren/ml-from-scratch/tree/master/mlfromscratch/unsupervised_learning): `mlfromscratch/unsupervised_learning`

### Deep Learning

- [Neural network](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/neural_network.py): `mlfromscratch/deep_learning/neural_network.py`
- [Network layers](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/layers.py): `mlfromscratch/deep_learning/layers.py`
- [Activations](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/activation_functions.py): `mlfromscratch/deep_learning/activation_functions.py`
- [Loss functions](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/loss_functions.py): `mlfromscratch/deep_learning/loss_functions.py`
- [Optimizers](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/deep_learning/optimizers.py): `mlfromscratch/deep_learning/optimizers.py`

### Reinforcement Learning

- [Deep Q-network](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/reinforcement_learning/deep_q_network.py): `mlfromscratch/reinforcement_learning/deep_q_network.py`

### Shared Utilities

- [Data manipulation](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/data_manipulation.py): `mlfromscratch/utils/data_manipulation.py`
- [Data operations](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/data_operation.py): `mlfromscratch/utils/data_operation.py`
- [Plotting helpers](https://github.com/eriklindernoren/ml-from-scratch/blob/master/mlfromscratch/utils/misc.py): `mlfromscratch/utils/misc.py`

### Other components

- **Library user**
- **Training data**
- **Model results**
- **Gym environment**

## Connections

- Library user → Supervised algorithms: selects model (evidence: `README.md`)
- Library user → Unsupervised algorithms: selects model (evidence: `README.md`)
- Library user → Neural network: trains network (evidence: `README.md`)
- Library user → Deep Q-network: trains agent (evidence: `README.md`)
- Training data → Supervised algorithms: provides examples
- Training data → Unsupervised algorithms: provides examples
- Supervised algorithms → Model results: produces predictions
- Unsupervised algorithms → Model results: produces patterns
- Neural network → Model results: produces predictions
- Decision trees → Data manipulation: calls helpers (evidence: `mlfromscratch/supervised_learning/decision_tree.py`)
- Boosting models → Decision trees: uses trees (evidence: `mlfromscratch/supervised_learning/gradient_boosting.py`)
- Boosting models → Loss functions: uses loss (evidence: `mlfromscratch/supervised_learning/gradient_boosting.py`)
- Association mining → Model results: returns rules (evidence: `mlfromscratch/unsupervised_learning/apriori.py`)
- Density clustering → Data manipulation: imports utilities (evidence: `mlfromscratch/unsupervised_learning/dbscan.py`)
- Gaussian mixtures → Data manipulation: imports utilities (evidence: `mlfromscratch/unsupervised_learning/gaussian_mixture_model.py`)
- Medoid clustering → Data manipulation: imports utilities (evidence: `mlfromscratch/unsupervised_learning/partitioning_around_medoids.py`)
- Network layers → Activations: imports functions (evidence: `mlfromscratch/deep_learning/layers.py`)
- Loss functions → Activations: imports function (evidence: `mlfromscratch/deep_learning/loss_functions.py`)
- Loss functions → Data manipulation: imports accuracy (evidence: `mlfromscratch/deep_learning/loss_functions.py`)
- Optimizers → Data manipulation: imports helpers (evidence: `mlfromscratch/deep_learning/optimizers.py`)
- Deep Q-network → Gym environment: steps environment (evidence: `mlfromscratch/reinforcement_learning/deep_q_network.py`)
- Data manipulation → Data operations: reexports operations (evidence: `mlfromscratch/utils/__init__.py`)
- Plotting helpers → Data operations: computes covariance (evidence: `mlfromscratch/utils/misc.py`)
- Plotting helpers → Data manipulation: standardizes data (evidence: `mlfromscratch/utils/misc.py`)
