Skip to main content

Decision tree classifier with centroid-asymmetry split criterion

Project description

asymtree

A scikit-learn compatible decision tree classifier that rewards splits where one side's centroid is pulled far from the splitting boundary — centroid asymmetry.

Motivation

Standard decision trees choose splits purely on impurity (Gini / entropy). A split that perfectly separates classes but places both centroids equidistant from the boundary is treated the same as one where nearly all of one class is packed tightly on one side. asymtree exposes this asymmetry as an explicit objective, so you can tune how aggressively the tree favors interpretable, one-sided splits.

Mathematical background

For a candidate split on feature k at threshold t, with left samples
L = {x : x_k ≤ t} and right samples R = {x : x_k > t}, define:

asymmetry(k, t) = max(t − μ_L, μ_R − t) / (x_k_max − x_k_min)

where μ_L and μ_R are the feature-k means on each side. The denominator normalises by the feature range so scores are comparable across features and always lie in [0, 1].

Two combination strategies

Additive — score the split as a weighted sum:

score(k, t) = ΔGini(k, t) + λ · asymmetry(k, t)

Lexicographic — among all splits within ε of the best Gini improvement, pick the one with the highest asymmetry. Purity and asymmetry are fully decoupled.

Efficient implementation

μ_L and μ_R are maintained as running sums while the threshold scan moves left to right, giving the same O(n) cost per feature as the standard split search — no extra pass over the data.

Installation

pip install asymtree

Requirements: Python ≥ 3.9, scikit-learn ≥ 1.4, numpy ≥ 1.21.
A C compiler and Cython ≥ 3.0 are needed to build from source.

Quick start

from asymtree import AsymmetryDecisionTreeClassifier

# Additive mode: impurity + 0.5 × asymmetry
clf = AsymmetryDecisionTreeClassifier(
    max_depth=4,
    lambda_=0.5,
    lexicographic=False,
    random_state=42,
)
clf.fit(X_train, y_train)
print(clf.score(X_test, y_test))

# Lexicographic mode: purity first, asymmetry breaks ties
clf_lexico = AsymmetryDecisionTreeClassifier(
    max_depth=4,
    eps_impurity=1e-3,
    lexicographic=True,
    random_state=42,
)
clf_lexico.fit(X_train, y_train)

Parameters

Parameter Type Default Description
lambda_ float 1.0 Weight of the asymmetry term (additive mode only).
eps_impurity float 1e-4 Tolerance band for lexicographic tiebreaking.
lexicographic bool False If True, use lexicographic mode.
max_depth int | None None Maximum tree depth.
min_samples_split int 2 Minimum samples to split a node.
min_samples_leaf int 1 Minimum samples in a leaf.
max_features int | float | str | None None Number of features to consider per split.
random_state int | None None Random seed.

All other DecisionTreeClassifier parameters are forwarded unchanged.

Compatibility

AsymmetryDecisionTreeClassifier is a drop-in replacement for sklearn.tree.DecisionTreeClassifier and works with all sklearn utilities: cross-validation, pipelines, clone, GridSearchCV, plot_tree, etc.

from sklearn.model_selection import GridSearchCV

param_grid = {"max_depth": [3, 4, 5], "lambda_": [0.1, 0.5, 1.0]}
gs = GridSearchCV(AsymmetryDecisionTreeClassifier(), param_grid, cv=5)
gs.fit(X_train, y_train)

Running the tests

pip install pytest
pytest tests/

License

MIT

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

asymtree-0.1.9.tar.gz (183.7 kB view details)

Uploaded Source

Built Distributions

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

asymtree-0.1.9-cp312-cp312-win_amd64.whl (255.9 kB view details)

Uploaded CPython 3.12Windows x86-64

asymtree-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (616.2 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

asymtree-0.1.9-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (594.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

asymtree-0.1.9-cp312-cp312-macosx_11_0_arm64.whl (261.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

asymtree-0.1.9-cp311-cp311-win_amd64.whl (254.9 kB view details)

Uploaded CPython 3.11Windows x86-64

asymtree-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (593.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

asymtree-0.1.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (575.9 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

asymtree-0.1.9-cp311-cp311-macosx_11_0_arm64.whl (260.8 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

asymtree-0.1.9-cp310-cp310-win_amd64.whl (254.9 kB view details)

Uploaded CPython 3.10Windows x86-64

asymtree-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (572.2 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

asymtree-0.1.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (552.4 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

asymtree-0.1.9-cp310-cp310-macosx_11_0_arm64.whl (260.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

asymtree-0.1.9-cp39-cp39-win_amd64.whl (255.2 kB view details)

Uploaded CPython 3.9Windows x86-64

asymtree-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (571.1 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

asymtree-0.1.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl (551.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ i686manylinux: glibc 2.5+ i686

asymtree-0.1.9-cp39-cp39-macosx_11_0_arm64.whl (261.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file asymtree-0.1.9.tar.gz.

File metadata

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

File hashes

Hashes for asymtree-0.1.9.tar.gz
Algorithm Hash digest
SHA256 c476877442f50957dc2810d49df0108ce1a7eab9f6a4bc951d28f305197e8c9b
MD5 75e3457991fc416f2b6ed086e2d256de
BLAKE2b-256 3576fb31578323f009be7e1cd14629bf6ab2044f03a65453149bdd36e27b3898

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9.tar.gz:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.9-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 255.9 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asymtree-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ce922119910b866729bb5c2e349294af894ab93d4b34ad09a9080aa9afa78433
MD5 e9eab04346a653fd7cd7b220c209056a
BLAKE2b-256 81ebcc1fca2b4fe05506ae840177c1139e32bbb100a04cd7baa45010ff382246

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3f4dc39fea56496d918b338a9199644220ee7a93a2f09aeba6475d1a05150944
MD5 972663cbf7fa78b85489fe5193eed381
BLAKE2b-256 8b86fd782abc8e303edd9bbadf84adbde8e4bd54deaf239f03ab0648d1de593c

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 89bc7d770e966c40e1f34fdcd509f981b1edb4285f76205d39d2434e43b45254
MD5 6cdda428da7e39d8ba3247b9937863fa
BLAKE2b-256 c0c9d7262cbd4de1c60d9d4fddc1eb5ebbc9db86508ebff74df46013fd9635b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7860d3b8ea243378c85a400b1c78a2e737ad3ef2c93cd61be36f587a60dc30bd
MD5 06fc161e766f6e104257b7229a27a571
BLAKE2b-256 701018cefbcf75c460f7c2d53ef970e39a33d2a50701bf5941aa76137ac74b7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.9-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 254.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asymtree-0.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2114f6c8a4862877d1d55f77c30a13407c7ac007b04c2fd78898fd5aa9a5bd5e
MD5 73e2489353820232fdc63d7c5fb9f3d7
BLAKE2b-256 51f2729221d72f3852d0d184ab9ea8293da22c5ed803a11835b047547a6c6bb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp311-cp311-win_amd64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 448d7f3a58684025b3db92744d6c8da7dc5af1a3adb4b0f7245c48b42ab36a7a
MD5 557b697a156cffd9799093109a4dc216
BLAKE2b-256 f84b787b23da6600c63cb191b42ae6dfa9746bf015e5b2e6cf610b21fe8c8d22

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 95cc34b4f454d2405a630b690801bfe05058f65a336d71fe88ec876f9bba3f3e
MD5 ed4f2749a6c623a386b54517fce62632
BLAKE2b-256 6823319ce23b51e022f7dffcc258cd2aace8c78bacacfd63fb8f42553e390935

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 bac128af83bb87fc5b361e77c2d6840cd5b8d6929ed3bc3941072a2dded8dbe4
MD5 4ff294289cf87161b7d0a836b8f7e517
BLAKE2b-256 7552231c31c0b98caa87b5afda55ba234962cebc888d590327dfda8429987690

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.9-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 254.9 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asymtree-0.1.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 37b43e0a31b2b94d5c680180585f941650e0e41d0fb87023846c0e3b2db9b12d
MD5 3e149824996e9d5fec0d76df606ccc2a
BLAKE2b-256 970f871bdc1d16d20beb07fc9ba0ce28cdad06c7b0816994d8f2342a63266407

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp310-cp310-win_amd64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef69a573759a8c4ca966d993b0fa72df6e28665b3fdecc26875575c0a7d5b90b
MD5 75b8659ee1ff9327e4d305b93d612f74
BLAKE2b-256 f0e488d216655a3cab6fe52e23372de369230d3026283170ec827b730ef752ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 92f7eb8aee4a052b14d042e748587683901738d2600a74409b04a3e885401407
MD5 7e554cc0f5f3dcfe337f5cf7c8988f86
BLAKE2b-256 12da4f6bbb5c7587ad78fdc50ad16b204a6ece48634c65b4b04d508bdb86d646

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4b275660adab7d53e5340034677a7df458882aa6c4d6faaeb7cb907e1abb502
MD5 34069c571fdfac293e65f509397aca12
BLAKE2b-256 dcfba0c6fe384c16269765d32f42ecc7ddbed7b9c55dead5f5b316899b5e5221

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.9-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 255.2 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asymtree-0.1.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 0092ec922ce60ec5c76a56ebf43128dbcb5414eeb054de0d96ea92a384a963c2
MD5 537ed7378388e3acbc6297e691f84931
BLAKE2b-256 1056be0133d0dcb6dc2f7950726c6692f822af67304af70bc58bf37a71ecea5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp39-cp39-win_amd64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e4cc98b10c83ee5d17007359299b26919d375aa8c9cd72be15c219fa5673c864
MD5 e6cb3437ea853a76a1ab878c1ac4d88d
BLAKE2b-256 e9eb81f06cc1529ffa7c50379676d3ea8b82e3b4429a057ed75e508e68bc2a4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 fb0216f7bd98a74b07da7778da96098e409cfab5bb1422b6f4217c8bd481f4dc
MD5 7d717fa3be12c23b18667631b8570ed4
BLAKE2b-256 02e45af7278f5b623e957de055e59f2b7e8a442619b84d2ccb3f34ca1f6bdf48

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl:

Publisher: publish.yml on lcsnxn/asymtree

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

File details

Details for the file asymtree-0.1.9-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.9-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f1d008e2ecdd8d7950bc314e746c797503534f8afcb14826aed1c4da7933b26
MD5 42ceb9b35e9049100675fedb01d9a471
BLAKE2b-256 0cce58555b6c42d05e49943e06789f74490d8953800dcf2f86d774e023280de1

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.9-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: publish.yml on lcsnxn/asymtree

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