Skip to main content

Shallow decision trees for explainable clustering

Project description

ShallowTree

Implementation of the ExShallow algoritm from Shallow decision trees for explainable k-means clustering, the goal of which is to find a decision tree inducing a partition of the data that is both good (in terms of the k-means cost) and explainable (in terms of being defined by a shallow tree).

Installation

pip install ShallowTree

Example

from ShallowTree.ShallowTree import ShallowTree
from sklearn.datasets import load_iris
from sklearn.cluster import KMeans

# test on the iris dataset
iris = load_iris()
data = iris.data
k = len(iris.target_names)

# create a tree that will partition the data into k clusters
tree = ShallowTree(k)

# define a KMeans instance and feed it to the tree
km = KMeans(k, random_state=1)
km.fit(data)

tree.fit(data, km)

# alternatively, fit the tree immediately;
# kmeans will run internally
tree.fit(data)

# return the score of the ttree fit and compare
# it to the score of the k-means partition
tree_score = tree.score(data)
km_score = -km.score(data)

print(tree_score / km_score)

# Construct the tree, and return cluster labels
prediction = tree.fit_predict(X)

# Tree plot saved to filename
tree.plot('filename')

Citation

@article{laber2021shallow,
    title={Shallow decision trees for explainable $k$-means clustering},
    author={Laber, Eduardo and Murtinho, Lucas and Oliveira, Felipe},
    journal={arXiv preprint arXiv:2112.14718},
    year={2021}
}

Contact

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

ShallowTree-0.0.10.tar.gz (11.3 kB view details)

Uploaded Source

File details

Details for the file ShallowTree-0.0.10.tar.gz.

File metadata

  • Download URL: ShallowTree-0.0.10.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.10

File hashes

Hashes for ShallowTree-0.0.10.tar.gz
Algorithm Hash digest
SHA256 6d1ef09b1d36e9fc151ce5278b3ac2aa48e9e0ea7d64d6bdb01ecc6160d90b2b
MD5 b0b561c9808dcea2beb4f1d65ed6d487
BLAKE2b-256 1f3ebb3ae1583d81a0c404d705445ec85a295fce591d1c7fcebe90a64f0c65c9

See more details on using hashes here.

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