Decision tree from scratch
A small Python classification tree for the decision-tree assignment. The splitting algorithm uses entropy and information gain. It does not use scikit-learn, NumPy, or a prebuilt tree implementation.
Run the example
Python 3.10 or newer is required. From the project folder:
python example.py
python -m unittest discover -s tests -v
The example uses the 14-row Play Tennis table from class. The Day column is excluded because it is only an identifier. It prints the results for different depth limits and displays the tree.
Use the class
from simple_tree import DecisionTree
X = [{"temperature": 10}, {"temperature": 15}, {"temperature": 25}, {"temperature": 30}]
y = ["Cold", "Cold", "Warm", "Warm"]
tree = DecisionTree(max_depth=2)
tree.fit(X, y)
print(tree.predict([{"temperature": 20}]))
print(tree.display())
Input rows are dictionaries. Class labels and categorical values must be hashable, such as strings or integers. Numeric values are split at candidate thresholds; strings and booleans are treated as categories. Missing training values and non-finite numeric values are rejected. At prediction time, a missing feature or an unseen category uses the current node's majority class.
max_depth controls the longest path from the root to a leaf. Root depth is zero. This limits tree depth, not the exact number of nodes: a categorical split can have several children. Equal class counts are resolved by first appearance; equal gains keep the first candidate.
Files
simple_tree/tree.py: entropy, information gain, training, prediction and text display.example.pyanddata/tennis.csv: the classroom example.tests/test_tree.py: nine tests.report.md: short assignment report.pyproject.toml: installable package metadata.
Package
Published releases are available on PyPI.
Install locally with python -m pip install .. Distribution name: fateh-simple-decision-tree; import name: simple_tree.
Build and check a distribution:
python -m pip install build twine
python -m build
python -m twine check dist/*
To publish, the owner needs a PyPI account and permission to create this package:
python -m twine upload dist/*
The manually triggered GitHub Actions workflow .github/workflows/publish.yml builds, tests and publishes releases using PyPI Trusted Publishing.
Package page: https://pypi.org/project/fateh-simple-decision-tree/
Install a published release with python -m pip install fateh-simple-decision-tree.
Limits
This is an educational implementation for small datasets. It checks candidate numeric thresholds directly, which is slow for large datasets. There is no pruning after training, missing-value imputation, or probability prediction. The tree stops if no split has positive gain; this can miss patterns such as XOR. The example's training accuracy is not an estimate of performance on unseen data.
Metadata
Release files for fateh-simple-decision-tree 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fateh_simple_decision_tree-0.1.1.tar.gz | 7.9 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fateh_simple_decision_tree-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.6 kB
Release files / fateh_simple_decision_tree-0.1.1.tar.gz
| Download URL | fateh_simple_decision_tree-0.1.1.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3eda2f3849c5a3d58ad19ce65db199ffe488929e4dc7c79902319c02760c0ef4
|
|
BLAKE2b-256 checksum How to use checksums |
9bd247d035f4245794d7f95642c82381aba923e7a3a1b9f6667564fa8aa99308
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logRelease files / fateh_simple_decision_tree-0.1.1-py3-none-any.whl
| Download URL | fateh_simple_decision_tree-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f193f2ea506fe9e9d02b3c8b0ee2fd383c7736b26aabd035a76dc902851cada
|
|
BLAKE2b-256 checksum How to use checksums |
7d7332ac8c363707c4b16456f67bffecbd94aee060a72f89146eecba9f7f9fe8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logSecurity for fateh-simple-decision-tree 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for fateh_simple_decision_tree-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.