Skip to main content

Building Decision Trees with Constraints

Project description

# Decision Tree Constraints

This is a sample code of the `PruneToSizeK` method for sklearn [Decision Tree Classifier](https://scikit-learn.org/stable/modules/tree.html).

Usage:
```
from sklearn.datasets import load_iris
from sklearn import tree
from DecisionTreeConstraints import SizeConstraintPruning

iris = load_iris()
clf = tree.DecisionTreeClassifier()
clf = clf.fit(iris.data, iris.target)

MAX_SIZE=6
SizeConstraintPruning(MAX_SIZE).pruneToSizeK(clf)

accuracy = clf.score(iris.data, iris.target)
print('Training accuracy for max size %s: %.3f' % (MAX_SIZE, accuracy))
```

Garofalakis, M., Hyun, D., Rastogi, R. et al. Data Mining and Knowledge Discovery (2003) 7: 187. [doi:10.1023](https://doi.org/10.1023/A:1022445500761).


Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

DecisionTreeConstraints-0.1.tar.gz (2.6 kB view hashes)

Uploaded Source

Built Distributions

DecisionTreeConstraints-0.1-py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 3

DecisionTreeConstraints-0.1-py2.py3-none-any.whl (4.8 kB view hashes)

Uploaded Python 2 Python 3

Supported by

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