# yuze-li2026/stat-learning-numpy architecture

> Architecture diagram of the GitHub repository yuze-li2026/stat-learning-numpy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuze-li2026/stat-learning-numpy
- Repository: https://github.com/yuze-li2026/stat-learning-numpy

## Overview

This repository is a chapter-by-chapter, pure-NumPy implementation of the core algorithms in *Statistical Learning Methods* (2nd edition). The main workflow is to run a chapter demo, which prepares example data, fits or applies that chapter’s algorithm, and reports or plots results. The README documents all chapter topics and the shared cached-data helper; sampled demos confirm selected data and model calls. Most chapter implementations were not excerpted, so those are shown as documented capabilities without inferred internal links.

Main entry points: [`common/datasets.py`](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/common/datasets.py) (Dataset cache), [`ch03-knn/model.py`](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch03-knn/model.py) (kNN and KD tree), [`ch15-svd/model.py`](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch15-svd/model.py) (SVD), [`ch16-pca/model.py`](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch16-pca/model.py) (PCA)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_supervised["Supervised learning"]
  node_perceptron["Perceptron<br/>[model.py]"]
  node_knn["kNN and KD tree<br/>[model.py]"]
  node_naivebayes["Naive Bayes<br/>[model.py]"]
  node_bayesestimate["Bayes estimation<br/>[model.py]"]
  node_tree["Decision trees<br/>[model.py]"]
  node_logistic["Logistic and maxent<br/>[model.py]"]
  node_svm["SVM<br/>[model.py]"]
  node_boosting["AdaBoost<br/>[model.py]"]
end

subgraph group_probabilistic["Probabilistic models"]
  node_em["EM and mixtures<br/>[model.py]"]
  node_hmm["Hidden Markov model<br/>[model.py]"]
  node_crf["Linear-chain CRF<br/>[model.py]"]
end

subgraph group_representations["Representations and clustering"]
  node_clustering["Clustering<br/>[model.py]"]
  node_svd["SVD<br/>[model.py]"]
  node_pca["PCA<br/>[model.py]"]
  node_lsa["LSA<br/>[model.py]"]
  node_plsa["PLSA<br/>[model.py]"]
end

subgraph group_sampling["Sampling and ranking"]
  node_mcmc["MCMC samplers<br/>[model.py]"]
  node_lda["LDA<br/>[model.py]"]
  node_pagerank["PageRank<br/>[model.py]"]
end

subgraph group_data["Data support"]
  node_datasethelper["Dataset cache<br/>[datasets.py]"]
  node_externaldata(("Public datasets"))
end

node_externaldata -->|"downloads and caches"| node_datasethelper
node_knn -->|"loads Iris"| node_datasethelper
node_svd -->|"fetches image"| node_datasethelper
node_pca -.->|"loads Iris"| node_datasethelper
node_lsa -->|"fetches corpus"| node_datasethelper
node_lda -->|"fetches corpus"| node_datasethelper
node_pagerank -->|"fetches network"| node_datasethelper

click node_perceptron "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch02-perceptron/model.py"
click node_knn "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch03-knn/model.py"
click node_naivebayes "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch04a-naive-bayes/model.py"
click node_bayesestimate "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch04b-bayes-estimation/model.py"
click node_tree "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch05-decision-tree/model.py"
click node_logistic "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch06-logistic-maxent/model.py"
click node_svm "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch07-svm/model.py"
click node_boosting "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch08-boosting/model.py"
click node_em "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch09-em/model.py"
click node_hmm "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch10-hmm/model.py"
click node_crf "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch11-crf/model.py"
click node_clustering "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch14-clustering/model.py"
click node_svd "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch15-svd/model.py"
click node_pca "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch16-pca/model.py"
click node_lsa "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch17-lsa/model.py"
click node_plsa "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch18-plsa/model.py"
click node_mcmc "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch19-mcmc/model.py"
click node_lda "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch20-lda/model.py"
click node_pagerank "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch21-pagerank/model.py"
click node_datasethelper "https://github.com/yuze-li2026/stat-learning-numpy/blob/main/common/datasets.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_perceptron,node_knn,node_naivebayes,node_bayesestimate,node_tree,node_logistic,node_svm,node_boosting toneBlue
class node_em,node_hmm,node_crf toneAmber
class node_clustering,node_svd,node_pca,node_lsa,node_plsa toneMint
class node_mcmc,node_lda,node_pagerank toneRose
class node_datasethelper,node_externaldata toneIndigo
```

## Components

### Supervised learning

- [Perceptron](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch02-perceptron/model.py): `ch02-perceptron/model.py`
- [kNN and KD tree](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch03-knn/model.py): `ch03-knn/model.py`
- [Naive Bayes](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch04a-naive-bayes/model.py): `ch04a-naive-bayes/model.py`
- [Bayes estimation](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch04b-bayes-estimation/model.py): `ch04b-bayes-estimation/model.py`
- [Decision trees](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch05-decision-tree/model.py): `ch05-decision-tree/model.py`
- [Logistic and maxent](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch06-logistic-maxent/model.py): `ch06-logistic-maxent/model.py`
- [SVM](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch07-svm/model.py): `ch07-svm/model.py`
- [AdaBoost](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch08-boosting/model.py): `ch08-boosting/model.py`

### Probabilistic models

- [EM and mixtures](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch09-em/model.py): `ch09-em/model.py`
- [Hidden Markov model](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch10-hmm/model.py): `ch10-hmm/model.py`
- [Linear-chain CRF](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch11-crf/model.py): `ch11-crf/model.py`

### Representations and clustering

- [Clustering](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch14-clustering/model.py): `ch14-clustering/model.py`
- [SVD](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch15-svd/model.py): `ch15-svd/model.py`
- [PCA](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch16-pca/model.py): `ch16-pca/model.py`
- [LSA](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch17-lsa/model.py): `ch17-lsa/model.py`
- [PLSA](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch18-plsa/model.py): `ch18-plsa/model.py`

### Sampling and ranking

- [MCMC samplers](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch19-mcmc/model.py): `ch19-mcmc/model.py`
- [LDA](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch20-lda/model.py): `ch20-lda/model.py`
- [PageRank](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/ch21-pagerank/model.py): `ch21-pagerank/model.py`

### Data support

- [Dataset cache](https://github.com/yuze-li2026/stat-learning-numpy/blob/main/common/datasets.py): `common/datasets.py`
- **Public datasets**

## Connections

- Public datasets → Dataset cache: downloads and caches (evidence: `common/datasets.py`)
- kNN and KD tree → Dataset cache: loads Iris
- SVD → Dataset cache: fetches image
- PCA → Dataset cache: loads Iris
- LSA → Dataset cache: fetches corpus
- LDA → Dataset cache: fetches corpus
- PageRank → Dataset cache: fetches network
