# mahmoudewida/decision-trees-cart-checked-against-scikit-learn architecture

> Architecture diagram of the GitHub repository mahmoudewida/decision-trees-cart-checked-against-scikit-learn, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn
- Repository: https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn

## Overview

This is a small educational CART walkthrough, not a deployed service. Running `scaffold.py` drives four stages: hand-built classification checked against scikit-learn, classification experiments on moons, regression-tree evaluation, and an Iris model save/reload followed by species prediction. `model.py` contains both the hand-built algorithm and scikit-learn-backed helpers. The graph follows documented calls and sampled source; external libraries and datasets are shown only where their use is explicit.

Main entry points: [`scaffold.py`](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/scaffold.py) (Run walkthrough), [`model.py`](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py) (Compare trees)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runner["Walkthrough"]
  node_scaffold["Run walkthrough<br/>[scaffold.py]"]
  node_result["Printed results<br/>[scaffold.py]"]
end

subgraph group_cart["CART Classification"]
  node_gini["Gini impurity<br/>[model.py]"]
  node_best_split["Best split<br/>[model.py]"]
  node_grow_tree["Grow CART<br/>[model.py]"]
  node_predict_tree["Predict CART<br/>[model.py]"]
  node_sklearn_fit["Fit classifier<br/>[model.py]"]
  node_compare["Compare trees<br/>[model.py]"]
end

subgraph group_experiments["Model Experiments"]
  node_moons["Moons split<br/>[model.py]"]
  node_regularization["Overfit comparison<br/>[model.py]"]
  node_rotation["Rotation sensitivity<br/>[model.py]"]
  node_regression["Regression tree<br/>[model.py]"]
end

subgraph group_serving["Model Serving"]
  node_rules["Export rules<br/>[model.py]"]
  node_save_reload["Save and reload<br/>[model.py]"]
  node_species["Predict species<br/>[model.py]"]
end

node_user(("Engineer"))
node_iris["Iris dataset"]
node_sklearn["scikit-learn"]
node_joblib["Joblib"]

node_user -->|"runs"| node_scaffold
node_scaffold -->|"loads"| node_iris
node_scaffold -->|"calls"| node_gini
node_scaffold -->|"calls"| node_best_split
node_scaffold -->|"calls"| node_compare
node_scaffold -->|"calls"| node_sklearn_fit
node_scaffold -->|"calls"| node_rules
node_scaffold -->|"calls"| node_moons
node_scaffold -->|"calls"| node_regularization
node_scaffold -->|"calls"| node_rotation
node_scaffold -->|"calls"| node_regression
node_scaffold -->|"calls"| node_save_reload
node_scaffold -->|"calls"| node_species
node_scaffold -->|"prints"| node_result
node_best_split -->|"scores"| node_gini
node_grow_tree -->|"selects split"| node_best_split
node_grow_tree -->|"recurses"| node_grow_tree
node_predict_tree -->|"traverses"| node_predict_tree
node_compare -->|"builds"| node_grow_tree
node_compare -->|"fits"| node_sklearn_fit
node_compare -->|"predicts"| node_predict_tree
node_sklearn_fit -->|"fits classifier"| node_sklearn
node_moons -->|"generates and splits data"| node_sklearn
node_regularization -->|"fits classifiers"| node_sklearn
node_rotation -->|"fits classifiers"| node_sklearn_fit
node_regression -->|"fits regressor"| node_sklearn
node_rules -->|"exports text"| node_sklearn
node_save_reload -->|"dumps and loads"| node_joblib
node_species -->|"predicts"| node_sklearn

click node_scaffold "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/scaffold.py"
click node_gini "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_best_split "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_grow_tree "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_predict_tree "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_sklearn_fit "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_compare "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_moons "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_regularization "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_rotation "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_regression "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_rules "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_save_reload "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_species "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py"
click node_result "https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/scaffold.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_scaffold,node_result toneBlue
class node_gini,node_best_split,node_grow_tree,node_predict_tree,node_sklearn_fit,node_compare toneAmber
class node_moons,node_regularization,node_rotation,node_regression toneMint
class node_rules,node_save_reload,node_species toneRose
class node_user,node_iris,node_sklearn,node_joblib toneIndigo
```

## Components

### Walkthrough

- [Run walkthrough](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/scaffold.py): `scaffold.py`
- [Printed results](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/scaffold.py): `scaffold.py`

### CART Classification

- [Gini impurity](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Best split](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Grow CART](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Predict CART](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Fit classifier](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Compare trees](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`

### Model Experiments

- [Moons split](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Overfit comparison](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Rotation sensitivity](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Regression tree](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`

### Model Serving

- [Export rules](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Save and reload](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`
- [Predict species](https://github.com/mahmoudewida/decision-trees-cart-checked-against-scikit-learn/blob/main/model.py): `model.py`

### Other components

- **Engineer**
- **Iris dataset**
- **scikit-learn**
- **Joblib**

## Connections

- Engineer → Run walkthrough: runs
- Run walkthrough → Iris dataset: loads
- Run walkthrough → Gini impurity: calls
- Run walkthrough → Best split: calls
- Run walkthrough → Compare trees: calls
- Run walkthrough → Fit classifier: calls
- Run walkthrough → Export rules: calls
- Run walkthrough → Moons split: calls
- Run walkthrough → Overfit comparison: calls
- Run walkthrough → Rotation sensitivity: calls
- Run walkthrough → Regression tree: calls
- Run walkthrough → Save and reload: calls
- Run walkthrough → Predict species: calls
- Run walkthrough → Printed results: prints
- Best split → Gini impurity: scores
- Grow CART → Best split: selects split
- Grow CART → Grow CART: recurses
- Predict CART → Predict CART: traverses
- Compare trees → Grow CART: builds
- Compare trees → Fit classifier: fits
- Compare trees → Predict CART: predicts
- Fit classifier → scikit-learn: fits classifier
- Moons split → scikit-learn: generates and splits data
- Overfit comparison → scikit-learn: fits classifiers
- Rotation sensitivity → Fit classifier: fits classifiers
- Regression tree → scikit-learn: fits regressor
- Export rules → scikit-learn: exports text
- Save and reload → Joblib: dumps and loads
- Predict species → scikit-learn: predicts
