infogain-tree
A decision tree classifier written from scratch with numpy and pandas. It picks splits by entropy and information gain.
- Numeric features get binary threshold splits (
x <= t). Categorical features get multiway splits (one branch per category, as in ID3). - The size of the tree is controlled by hyperparameters:
max_depth,min_samples_split,min_samples_leaf,min_information_gain,max_leaf_nodes. - Three ways to display the tree: text (
print_tree()), matplotlib (plot()), Graphviz (to_dot()). - Two example datasets are included:
load_play_tennis()andload_loan_approval().
Installation
pip install infogain-tree # from PyPI
pip install "infogain-tree[plot]" # with matplotlib, for tree.plot()
# or, from a clone of this repository:
pip install -e ".[plot]"
The package installs as infogain-tree and is imported as entropy_tree.
Quick start
from entropy_tree import DecisionTreeClassifier, load_play_tennis
df = load_play_tennis()
tree = DecisionTreeClassifier(max_depth=3).fit(df, "play") # "play" is the target column
tree.print_tree()
split on 'outlook' (n=14, H=0.940, IG=0.247)
├── outlook = overcast → predict 'yes' (n=4, H=0.000, counts=no:0 yes:4)
├── outlook = rainy → split on 'windy' (n=5, H=0.971, IG=0.971)
│ ├── windy = False → predict 'yes' (n=3, H=0.000, counts=no:0 yes:3)
│ └── windy = True → predict 'no' (n=2, H=0.000, counts=no:2 yes:0)
└── outlook = sunny → split on 'humidity' (n=5, H=0.971, IG=0.971)
├── humidity = high → predict 'no' (n=3, H=0.000, counts=no:3 yes:0)
└── humidity = normal → predict 'yes' (n=2, H=0.000, counts=no:0 yes:2)
tree.predict(df.drop(columns="play")) # labels
tree.predict_proba(df.drop(columns="play")) # class probabilities (order: tree.classes_)
tree.score(df.drop(columns="play"), df["play"])
tree.plot() # matplotlib figure
open("tree.dot", "w").write(tree.to_dot()) # Graphviz
fit(X, y) also takes a numpy array or a separate label vector:
DecisionTreeClassifier().fit(X, y).
API
| Item | Description |
|---|---|
DecisionTreeClassifier(max_depth=None, min_samples_split=2, min_samples_leaf=1, min_information_gain=0.0, max_leaf_nodes=None) |
The model |
.fit(X, y) / .predict(X) / .predict_proba(X) / .score(X, y) |
Train, predict, evaluate |
.get_depth(), .get_n_leaves(), .feature_importances_, .classes_, .root_ |
Inspect the tree |
.print_tree(), .export_text(), .plot(), .to_dot() |
Display the tree |
any_df_decision_tree(df, target_column, **params) |
One-call helper: build a tree from a DataFrame |
entropy(y), information_gain(parent, children) |
Impurity functions |
train_test_split, accuracy_score, confusion_matrix |
Small helpers, so scikit-learn is not needed |
load_play_tennis(), load_loan_approval() |
Example datasets |
Examples and tests
python examples/demo.py --plot # full walkthrough on both datasets
python -m unittest discover -s tests
See report.md for a description of the algorithm and results.
Metadata
Release files for infogain-tree 0.1.2
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 | |
|---|---|---|---|---|
| infogain_tree-0.1.2.tar.gz | 20.1 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| infogain_tree-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 37.9 kB
Release files / infogain_tree-0.1.2.tar.gz
| Download URL | infogain_tree-0.1.2.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a23983ca010e0461bfa8ab886f7bbca0893cc908834fef7a1fa3977d68b86780
|
|
BLAKE2b-256 checksum How to use checksums |
9bdd16637d3c5a32ed887d6faa8e07fbef96606225bfe72b7f477bfd2ada9df1
|
| 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 / infogain_tree-0.1.2-py3-none-any.whl
| Download URL | infogain_tree-0.1.2-py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f8f6b053f5d9433b10abdbba47a97e9ace89283cefa570f01c8d0c5b92ec875
|
|
BLAKE2b-256 checksum How to use checksums |
6fb5c8e4bafd9d3bd55dfb5f4c7c943b16df110cf2d1a6d4cedd47854b37157b
|
| 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 infogain-tree 0.1.2
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 infogain_tree-0.1.2.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.