Skip to main content

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 size
  • generations: evolution steps
  • crossover_rate: crossover fraction
  • mutation_rate: mutation fraction
  • elitist_rate: elite carryover fraction
  • max_depth: maximum tree depth
  • tournament_size: tournament selection size
  • selection_method: parent selection strategy ("tournament" or "pareto_tournament")
  • fitness_method: fitness objective ("accuracy" or "pearson_r2")
  • random_state: reproducibility seed
  • show_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:

  • "accuracy": maximize classification agreement (with inversion symmetry)
  • "pearson_r2": maximize squared Pearson correlation between predictions and labels

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

gpclassify-0.1.0.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpclassify-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file gpclassify-0.1.0.tar.gz.

File metadata

  • Download URL: gpclassify-0.1.0.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpclassify-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0eee670d41aadc33998025a4ce872fbe1ff3b621c4c90ec9f50d39f425fed7f2
MD5 2e7a721ed312f9a665a9fe8e57cc5947
BLAKE2b-256 190413301d655bd44ebc253729eb0af602e4e951535405b5ee2360891fa74489

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpclassify-0.1.0.tar.gz:

Publisher: workflow.yml on hoolagans/GPClassify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gpclassify-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: gpclassify-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for gpclassify-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32b5bb95bf86557305d7ba6cf4b3e47ce37ff575fbc9b9d28b70fdee329581ad
MD5 a7b3837f4c9c174a78ef06d909dfd453
BLAKE2b-256 74b3df2e588e3a73549632a3ecbede648ae9c3ecc089e0e9f63a960826673fc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpclassify-0.1.0-py3-none-any.whl:

Publisher: workflow.yml on hoolagans/GPClassify

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page