Decision Tree Genetic Programming classifier with a scikit-learn-style API.
Project description
GPClassify
Decision Tree Genetic Programming classifier with a scikit-learn-style API.
Install
pip install gpclassify
Quick start (binary classification)
from gpclassify import GPClassifier
X = [
[4.0, 1.0],
[5.0, 2.0],
[1.0, 3.0],
[2.0, 5.0],
]
y = [1 if row[0] > row[1] else 0 for row in X]
clf = GPClassifier(
num_models=40,
generations=40,
max_depth=6,
selection_method="pareto_tournament",
fitness_method="pearson_r2",
random_state=42,
)
clf.fit(X, y)
print(clf.predict(X))
print(clf.predict_proba(X))
print(clf.score(X, y))
Multiclass usage
GPClassifier supports multiclass classification with one-vs-rest training.
from gpclassify import GPClassifier
X = [
[9.0, 1.0, 1.0],
[1.0, 9.0, 1.0],
[1.0, 1.0, 9.0],
[8.0, 2.0, 1.0],
[1.0, 8.0, 2.0],
[2.0, 1.0, 8.0],
]
y = [0, 1, 2, 0, 1, 2]
clf = GPClassifier(num_models=20, generations=20, random_state=7)
clf.fit(X, y)
pred = clf.predict(X)
proba = clf.predict_proba(X)
Model inspection
You can inspect evolved models as expressions or tree-like text.
expr = clf.view_model() # one model as a readable expression
top3_expr = clf.view_model(3) # top 3 models as expressions
tree = clf.view_model_tree() # one model in tree-like format
top2_trees = clf.view_model_tree(2)
For multiclass one-vs-rest models, both inspection methods include class labels in the output so it is clear which class each displayed model belongs to.
Tree/value expression behavior
- Leaves are dataset variables (
x[i]) and numeric constants. - Comparison operands can include nested math layers (none, one, or many).
- Left and right sides are not required to be symmetric.
This allows regression-like value expressions at the bottom of boolean trees.
Main training parameters
num_models: population sizegenerations: evolution stepscrossover_rate: crossover fractionmutation_rate: mutation fractionelitist_rate: elite carryover fractionmax_depth: maximum tree depthtournament_size: tournament selection sizeselection_method: parent selection strategy ("tournament"or"pareto_tournament")fitness_method: fitness objective ("accuracy","f1_score", or"pearson_r2")random_state: reproducibility seedshow_training_curve: print generation-by-generation best fitness
Pareto tournament selection
Set selection_method="pareto_tournament" to optimize with two objectives during tournament
selection:
- maximize fitness (classification performance)
- minimize complexity (tree size)
For each tournament draw, GPClassify computes the full non-dominated front and samples parents from that front.
Fitness methods
Set fitness_method to choose the optimization target used by evolutionary scoring (default: "f1_score"):
"accuracy": maximize classification agreement (with inversion symmetry)"f1_score": maximize F1 score (with inversion symmetry)"pearson_r2": maximize squared Pearson correlation between predictions and labels
Citation
Haut, Nathan. Active Learning in Genetic Programming. Michigan State University, 2023.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gpclassify-0.1.5.tar.gz.
File metadata
- Download URL: gpclassify-0.1.5.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6073f2d67679a3188669f2c4dbdeff58f606185ab5fd288698bbb6bceaee9206
|
|
| MD5 |
53b09db54c67e2f151bd37951c003912
|
|
| BLAKE2b-256 |
15f76532286a9a9fe014165cd350d44b65a0a2f06cb49999af18cc423701ef65
|
Provenance
The following attestation bundles were made for gpclassify-0.1.5.tar.gz:
Publisher:
workflow.yml on hoolagans/GPClassify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gpclassify-0.1.5.tar.gz -
Subject digest:
6073f2d67679a3188669f2c4dbdeff58f606185ab5fd288698bbb6bceaee9206 - Sigstore transparency entry: 1549419248
- Sigstore integration time:
-
Permalink:
hoolagans/GPClassify@618ada562cd96efe90aa4cb54d1c8f628c6b848e -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/hoolagans
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@618ada562cd96efe90aa4cb54d1c8f628c6b848e -
Trigger Event:
release
-
Statement type:
File details
Details for the file gpclassify-0.1.5-py3-none-any.whl.
File metadata
- Download URL: gpclassify-0.1.5-py3-none-any.whl
- Upload date:
- Size: 11.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abe6601f62a52d44b94bbdfda484e1613424a3c128d10cde602ce80678a41fbb
|
|
| MD5 |
f9874437735e9be7078265883fbe4dcd
|
|
| BLAKE2b-256 |
c1e2b9d8b86c63fa277d59d45397ccdc2f1b53118237eb910cf38703f3d5e2eb
|
Provenance
The following attestation bundles were made for gpclassify-0.1.5-py3-none-any.whl:
Publisher:
workflow.yml on hoolagans/GPClassify
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gpclassify-0.1.5-py3-none-any.whl -
Subject digest:
abe6601f62a52d44b94bbdfda484e1613424a3c128d10cde602ce80678a41fbb - Sigstore transparency entry: 1549419334
- Sigstore integration time:
-
Permalink:
hoolagans/GPClassify@618ada562cd96efe90aa4cb54d1c8f628c6b848e -
Branch / Tag:
refs/tags/v1.0.5 - Owner: https://github.com/hoolagans
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@618ada562cd96efe90aa4cb54d1c8f628c6b848e -
Trigger Event:
release
-
Statement type: