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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.11macOS 11.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.10macOS 11.0+ ARM64

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

Uploaded CPython 3.9Windows x86-64

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

File metadata

  • Download URL: asymtree-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 42f3324655d9d3b420b2f9a904852657440e4a335eee652b708e5f95e61e7709
MD5 8f5d2005e6e3b38cfe9aa6ffff432cb1
BLAKE2b-256 16640fc9e18b3ce0def2105ef82e8099570f72f81c550fa06cb604c9971a9e87

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: asymtree-0.1.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5c42e31101ea5490256240defd0d5bd24ed4bfa51efe3dc67301bece67cae7d2
MD5 171de35060e7334972e42f112125b1f3
BLAKE2b-256 73bfafa02595d9ceacc48b4c8eef3eeb9ae37d9d3d07504d86e29f1edd9a409e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73283aacb39f9af54e7fb64a38a1fdc0bc3d1287eb582d74240e1f4bb8e08a90
MD5 4efce913210ffb892aeed438ddcdb93f
BLAKE2b-256 d767af1c99d7261d907fc9d7823ee10e0d8468b05df2e1271436edf8261861fc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4f97e63c698377e10630958fb826fc805bca8ca64d8f23ef2db22d2c9c71a650
MD5 5119e61ee27f41427f12795a552364a7
BLAKE2b-256 e747514c0e6a085f82e0c4f02a7d22cf87228adb7ab1889c83fc76ec1e4f1ce0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cfdf647f0cfad329e9a230c646fcd6ccada58b6a5df08c1ce1cfe0fef194c057
MD5 c2add634e1c4f9445360ae2349752d14
BLAKE2b-256 6fb60becf70a6b362d0301ff6a16ef50407a2063d9dad5fc8f6e3f8edd3544f4

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: asymtree-0.1.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d7db1f3ac1d0a2498bad203de69a1243506796d2f4f8f92424093384ea2976ff
MD5 dde30a73ce6f7ca05c67907e9949a7c9
BLAKE2b-256 35f2d29aaf2ede7107e24aa5172eded90ab3b889032b1801f2145c4a481a9b65

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8f0437dc11a2c9618705748d0a591992c8b8b4332044e0b62602b866d893227
MD5 8ec3b22b8ed69355578910503aa86c7a
BLAKE2b-256 4ef7c6ecd9710228817aca3d9d3174354c88f02e7922f457641567edb46d4796

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 61033b2e07a6dd5fdb4eb9b027ed5a6cc890c6ad4bcd3e047ce47eb6b1e95858
MD5 e3c9488956815386ba45a060859c0107
BLAKE2b-256 27c37772eca60567bc227b5399c960cb4f4261baa6ea5280c2525ca53554a084

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7998765d61f80e5bbd84b8de84b823da641e020f14f3078679576225d3c19b76
MD5 4f11a72942f47c23ca3103ba58992d6a
BLAKE2b-256 93b8683d03f6e5c8709910915558fa5c32b3a32aad6652567c5f2a3b578b0e1f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: asymtree-0.1.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d4a810a10475c73bf52876ed8a06efee61ac5013c597df0d40b8ff26c9ae730d
MD5 87210189c8351a9b485ae1ef70d4d878
BLAKE2b-256 f7659d65c2de4fe665c04aeb4b3e862b3bce84760e8bf209be9ce2b39d358acc

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8332f32dbc65d2a36f96c972b3dc13a20ff00f6958237e19ead6c581575cd7d7
MD5 c74611892bcf746b670fc2de40d7ac95
BLAKE2b-256 5ac7f98126b133372cc2ca040337befd7bdf21c97cf4fd7611d588f4bb332bfa

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 039022ab571a9cf1486e5d059d72641f1195688e10f79632b074a37104e58cb6
MD5 d1bbd4a931669b7cc5a3c8d62651f419
BLAKE2b-256 25b0809f70fcea0b88c6bf4a7920b40e8e51b7bd28ff337880809ed82174d22e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 26f73550c8a627b99c37cfbd5cf0001dd3217a6ab271e5ad8bb96f13f8f3bb59
MD5 a089e511cbd58c9747ae5f5d75b9da71
BLAKE2b-256 1118af568d9e5c6a6b9c58aeb2ddd3b1a4f7d4e6dd6735ae4179f0ea5bbb2f4e

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: asymtree-0.1.7-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.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 3898d6a4c28bf3cba49fe5384f5c990b019649410baad57b09d13a529cb569a2
MD5 d66accf0d8899ec044d1c49a6acd151b
BLAKE2b-256 8fdda980562a30865ef671bf7a25057ba77b4c8586cb82c8166f05f417fb3644

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 108b0290de48c8db034b0d92c4e2df7b7091c633f911efa81bd221ad6de6eea0
MD5 0c9c01565683340eb710b8086a43e47b
BLAKE2b-256 78dda6a9ea0e135df7e499f569dc25f293d767abd65c5fc761b051bdb75c7dad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b7e771683776c0a2497e3836780d858747ec3e64ae8538adc55bf6ceb69ccc04
MD5 89958790db77bd728bc64b6c746a5dfe
BLAKE2b-256 321e29ba0a8458d6492221f15922da71336a9230493a29106a9c392e0e487fcd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for asymtree-0.1.7-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 89f8f1192929233a67b72d015ff33678491ff9db49a37448daa97a0bdbbbbf21
MD5 7fe0cc47b86faf61838cc8aec9196dc0
BLAKE2b-256 527fdee1bc99d91cc1986396f63fd9202ce510041fdc6f40b961c0a7a79e34d4

See more details on using hashes here.

Provenance

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