# assemblyai-community/machine-learning-from-scratch architecture

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

- Interactive diagram: https://gitdiagram.com/assemblyai-community/machine-learning-from-scratch
- Repository: https://github.com/assemblyai-community/machine-learning-from-scratch

## Overview

This is an educational collection of machine-learning algorithms implemented from scratch, with small runnable demonstrations for several models. The typical demonstrated workflow loads a sample dataset, splits it into training and test data, fits an algorithm, predicts on held-out data, and reports a metric; some demos also plot results. The README describes the collection broadly but does not document a shared runtime or common pipeline. The remaining algorithm implementations are included as independent capabilities; their internal relationships are not inferred from unsampled code.

Main entry points: [`01 KNN/train.py`](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/01%20KNN/train.py) (KNN demo), [`02 Linear Regression/train.py`](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/02%20Linear%20Regression/train.py) (Linear regression demo), [`03 Logistic Regression/train.py`](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/03%20Logistic%20Regression/train.py) (Logistic regression demo), [`04 Decision Trees/train.py`](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/04%20Decision%20Trees/train.py) (Decision tree demo)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_examples["Runnable demos"]
  node_knn_demo["KNN demo<br/>[train.py]"]
  node_linear_demo["Linear regression demo<br/>[train.py]"]
  node_logistic_demo["Logistic regression demo<br/>[train.py]"]
  node_tree_demo["Decision tree demo<br/>[train.py]"]
  node_forest_demo["Random forest demo<br/>[train.py]"]
end

subgraph group_supervised["Supervised learning"]
  node_knn["KNN classifier<br/>[KNN.py]"]
  node_linear["Linear regression"]
  node_logistic["Logistic regression"]
  node_tree["Decision tree<br/>[DecisionTree.py]"]
  node_forest["Random forest<br/>[RandomForest.py]"]
  node_forest_tree["Forest tree<br/>[DecisionTree.py]"]
  node_naive_bayes["Naive Bayes<br/>[naive_bayes.py]"]
  node_perceptron["Perceptron<br/>[perceptron.py]"]
  node_svm["Support vector machine<br/>[svm.py]"]
end

subgraph group_unsupervised["Unsupervised learning"]
  node_kmeans["K-means clustering<br/>[kmeans.py]"]
end

subgraph group_representation["Representation learning"]
  node_pca["PCA<br/>[pca.py]"]
end

node_datasets[("Sample datasets")]
node_results["Predictions and metrics"]

node_datasets -->|"loads and splits"| node_knn_demo
node_knn_demo -->|"fits and predicts"| node_knn
node_knn_demo -->|"reports accuracy"| node_results
node_datasets -->|"generates and splits"| node_linear_demo
node_linear_demo -->|"fits and predicts"| node_linear
node_linear_demo -->|"reports error and plots"| node_results
node_datasets -->|"loads and splits"| node_logistic_demo
node_logistic_demo -->|"fits and predicts"| node_logistic
node_logistic_demo -->|"reports accuracy"| node_results
node_datasets -->|"loads and splits"| node_tree_demo
node_tree_demo -->|"fits and predicts"| node_tree
node_tree_demo -->|"reports accuracy"| node_results
node_datasets -->|"loads and splits"| node_forest_demo
node_forest_demo -->|"fits and predicts"| node_forest
node_forest_demo -->|"reports accuracy"| node_results
node_forest -->|"instantiates and trains"| node_forest_tree

click node_knn_demo "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/01%20KNN/train.py"
click node_linear_demo "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/02%20Linear%20Regression/train.py"
click node_logistic_demo "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/03%20Logistic%20Regression/train.py"
click node_tree_demo "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/04%20Decision%20Trees/train.py"
click node_forest_demo "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/05%20Random%20Forests/train.py"
click node_knn "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/01%20KNN/KNN.py"
click node_linear "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/02%20Linear%20Regression/LinearRegression.py"
click node_logistic "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/03%20Logistic%20Regression/LogisticRegression.py"
click node_tree "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/04%20Decision%20Trees/DecisionTree.py"
click node_forest "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/05%20Random%20Forests/RandomForest.py"
click node_forest_tree "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/05%20Random%20Forests/DecisionTree.py"
click node_naive_bayes "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/06%20NaiveBayes/naive_bayes.py"
click node_perceptron "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/08%20Perceptron/perceptron.py"
click node_svm "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/09%20SVM/svm.py"
click node_kmeans "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/10%20KMeans/kmeans.py"
click node_pca "https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/07%20PCA/pca.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_knn_demo,node_linear_demo,node_logistic_demo,node_tree_demo,node_forest_demo toneBlue
class node_knn,node_linear,node_logistic,node_tree,node_forest,node_forest_tree,node_naive_bayes,node_perceptron,node_svm,node_datasets toneAmber
class node_kmeans toneMint
class node_pca toneRose
class node_results toneIndigo
```

## Components

### Runnable demos

- [KNN demo](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/01%20KNN/train.py): `01 KNN/train.py`
- [Linear regression demo](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/02%20Linear%20Regression/train.py): `02 Linear Regression/train.py`
- [Logistic regression demo](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/03%20Logistic%20Regression/train.py): `03 Logistic Regression/train.py`
- [Decision tree demo](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/04%20Decision%20Trees/train.py): `04 Decision Trees/train.py`
- [Random forest demo](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/05%20Random%20Forests/train.py): `05 Random Forests/train.py`

### Supervised learning

- [KNN classifier](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/01%20KNN/KNN.py): `01 KNN/KNN.py`
- [Linear regression](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/02%20Linear%20Regression/LinearRegression.py): `02 Linear Regression/LinearRegression.py`
- [Logistic regression](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/03%20Logistic%20Regression/LogisticRegression.py): `03 Logistic Regression/LogisticRegression.py`
- [Decision tree](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/04%20Decision%20Trees/DecisionTree.py): `04 Decision Trees/DecisionTree.py`
- [Random forest](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/05%20Random%20Forests/RandomForest.py): `05 Random Forests/RandomForest.py`
- [Forest tree](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/05%20Random%20Forests/DecisionTree.py): `05 Random Forests/DecisionTree.py`
- [Naive Bayes](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/06%20NaiveBayes/naive_bayes.py): `06 NaiveBayes/naive_bayes.py`
- [Perceptron](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/08%20Perceptron/perceptron.py): `08 Perceptron/perceptron.py`
- [Support vector machine](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/09%20SVM/svm.py): `09 SVM/svm.py`

### Unsupervised learning

- [K-means clustering](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/10%20KMeans/kmeans.py): `10 KMeans/kmeans.py`

### Representation learning

- [PCA](https://github.com/assemblyai-community/machine-learning-from-scratch/blob/main/07%20PCA/pca.py): `07 PCA/pca.py`

### Other components

- **Sample datasets**
- **Predictions and metrics**

## Connections

- Sample datasets → KNN demo: loads and splits (evidence: `01 KNN/train.py`)
- KNN demo → KNN classifier: fits and predicts (evidence: `01 KNN/train.py`)
- KNN demo → Predictions and metrics: reports accuracy (evidence: `01 KNN/train.py`)
- Sample datasets → Linear regression demo: generates and splits (evidence: `02 Linear Regression/train.py`)
- Linear regression demo → Linear regression: fits and predicts (evidence: `02 Linear Regression/train.py`)
- Linear regression demo → Predictions and metrics: reports error and plots (evidence: `02 Linear Regression/train.py`)
- Sample datasets → Logistic regression demo: loads and splits (evidence: `03 Logistic Regression/train.py`)
- Logistic regression demo → Logistic regression: fits and predicts (evidence: `03 Logistic Regression/train.py`)
- Logistic regression demo → Predictions and metrics: reports accuracy (evidence: `03 Logistic Regression/train.py`)
- Sample datasets → Decision tree demo: loads and splits (evidence: `04 Decision Trees/train.py`)
- Decision tree demo → Decision tree: fits and predicts (evidence: `04 Decision Trees/train.py`)
- Decision tree demo → Predictions and metrics: reports accuracy (evidence: `04 Decision Trees/train.py`)
- Sample datasets → Random forest demo: loads and splits (evidence: `05 Random Forests/train.py`)
- Random forest demo → Random forest: fits and predicts (evidence: `05 Random Forests/train.py`)
- Random forest demo → Predictions and metrics: reports accuracy (evidence: `05 Random Forests/train.py`)
- Random forest → Forest tree: instantiates and trains (evidence: `05 Random Forests/RandomForest.py`)
