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.8.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.8-cp312-cp312-win_amd64.whl (255.9 kB view details)

Uploaded CPython 3.12Windows x86-64

asymtree-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (616.1 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

asymtree-0.1.8-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.8-cp312-cp312-macosx_11_0_arm64.whl (261.1 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

asymtree-0.1.8-cp311-cp311-win_amd64.whl (254.8 kB view details)

Uploaded CPython 3.11Windows x86-64

asymtree-0.1.8-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.8-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.8-cp311-cp311-macosx_11_0_arm64.whl (260.7 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

asymtree-0.1.8-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.8-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.8-cp310-cp310-macosx_11_0_arm64.whl (260.9 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

asymtree-0.1.8-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.8-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.8-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.8.tar.gz.

File metadata

  • Download URL: asymtree-0.1.8.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.8.tar.gz
Algorithm Hash digest
SHA256 85161b2a2ce360191f086f7cae147ae3928ce61114d44d72844b35f0100d82e4
MD5 f1a0edce22a54eeb82392d9aee06215b
BLAKE2b-256 299edfb7fdcbce01b2e2ec05e6205101ead0a89e649bad94eda6ca095fadc3c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8.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.8-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.8-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.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 47756161e1c4ea5575f040c130094da1b8f4d9e733c670598588d12568f581f0
MD5 5c66869409f0d1656cf726fdd0565c1b
BLAKE2b-256 1c6b5cc924a3ed5b36f8a967e1ee4184507c6695043e4a2b36b8ec74102c4598

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5f3be38a7ef4551ef5795198a27132ec26b79dda89376541bc28e89cd2f5cb0
MD5 68f4f0404a4cd34f6c5c562e81ae66fe
BLAKE2b-256 1cbdf90f54b2d2395d82952c6eba829b2d727426ceac1a9224b99ef21864e429

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 df36e10dfd31f48f97eeb2d5cf69f2bd93a143352dbe971a12238860f6fa5e2c
MD5 ad8b977356421859e39baded8ea22d88
BLAKE2b-256 1ba06f015457c7e9e9f67dae51b28e7becdb477a6389031bc1e6f7fdba708ecd

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5aa3856dd5dac95f2a9f8a2205479248ec30cc64e4c81a386550d71630017e2d
MD5 b2162fccb1049423a6f4c2fec503cce6
BLAKE2b-256 b452092e1c58147f49794f4cde032bd421ffd2640a9568e21dfda052b60a0f18

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.8-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 254.8 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.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 db238ed559d6c73a50faf1fd9554607888e508a24c4fd77ed8f014c38fd1f7a6
MD5 adc4f6aa3ea844f0e7d7ac7a0f86a6e9
BLAKE2b-256 a875fb8dd2ade43040f5ac66c7ce55a5f7f38f7ccc0f1d602e6a21a3bb7ebbe4

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c375c1bede9330ce6c63587a6046cacccb3dff4a38181a006e182702809558b4
MD5 d4f8b387853e46a4c96b268cf61d3c53
BLAKE2b-256 018416a5a6b073270fcf26379b5bdc1d460fec92cad820e8fd7f846c030b88ed

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6475079005e92853e00e2174c21415f5e533b6e0cd9ce0df9f91781ad3dfdbda
MD5 76c56cd710b131a76458547de42b62cc
BLAKE2b-256 9c155be03fbe36b1e6469b3c1e66f08397dc8a421b0999e4593c4e5ca587a364

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 25ebacfcbed7be47cd11a65664271572b846fdd742325e1aece520f4fe436ea0
MD5 aacfdb2c0840d01019acc761c766f86d
BLAKE2b-256 d38e2c34b5e530b00ea69e4410dcf751a7c33fd2384a2e100090dcd2e8907d6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.8-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.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 6ee8dca09bbc47c15817c70b86b8152467c31bf858e5f0957716129bb6af3342
MD5 cd44dad9d5e652889664116efaa5e99c
BLAKE2b-256 664068c86e3c4306c37e9db27fb9306bae51c07d9ece1f844711d2286d5a7c7f

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 37743a5d4642e94e53a9c03282120b991643c46734427b65509f16c561073f8d
MD5 1cbdf012a146960a56ee7cfe6f6fa651
BLAKE2b-256 2b1b06d5b624fe5701a0c5bf209cf5d3c9a94b289cf82c7acb45135f2fd154fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 33e618ca2c0f0084a22ecf6cd9af741ce48a5e34d0a47aa9e9d831d82701f7ea
MD5 c1f3ec354f07ac1e3ee22add3fac2c91
BLAKE2b-256 68bbdc9fb98fb7836354f658d9021731a3d56a92ad6bfbf6f71c865f8e6b75d2

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2b1ce63d9af6f56b0f484a4abe79eaf6c31df8d631981cafe60301fee62f4a4f
MD5 d860f0ddaf10dfb12ac6b06dbe9e7788
BLAKE2b-256 a483ca3f8543e56e74638d4d4148d1e4e051ae206ddf74be21590f0fee6e98b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: asymtree-0.1.8-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.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 96921d990a3031d50627fa1bde521bedbdbf05241969668be235cb6e8661958b
MD5 1c807bcf6b3738adc64c426b50b42ebd
BLAKE2b-256 b7f42fd66f3616b89330925193fbbf86db66466e022aa9f44d51c31fb7d420be

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8deaa5fb08cb00d683f9eff0bc316ad6755e3e58a4249c9105547424225c64f4
MD5 ed5b0efadd64ac94c98a26102df607e1
BLAKE2b-256 c56049c215c00b519ab90f5bfcefd278db91c26212533adaf0d070879c87908c

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 28201090068debe688927034abc6e994c2f63906ca74de2cc45e59faccbb45ae
MD5 7bd533f284514fba5f527cac04d50d9c
BLAKE2b-256 713677e25f5030e41d2edf26042672c70586fef3641ecc4de9f806e096f8a5e8

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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.8-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for asymtree-0.1.8-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2898ab1c407701e6e110660015d9e9fb48212211f7342baff5a4781af3c8aa78
MD5 1de7e8a387a6bceed426e02e74165f36
BLAKE2b-256 ea0ee5fc27b0838a25699bf69b89d6c9bd76020f16193df402fc58d99f660253

See more details on using hashes here.

Provenance

The following attestation bundles were made for asymtree-0.1.8-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