Skip to main content

Python Implementation of Bertsimas's paper Optimal Classification Trees.

Project description

# pyoptree
Python Optimal Tree

### Install
#### First install pyoptree through pip
```
pip3 install pyoptree
```

#### Then install solver (IMPORTANT!)
The user needs to have **IBM Cplex** or **Gurobi** installed on their computer, and make sure that **the executable has been added to PATH environment variable** (i.e. command `cplex` or `gurobi` can be run on terminal).

### Example
```python
import pandas as pd
from pyoptree.optree import OptimalHyperTreeModel, OptimalTreeModel

data = pd.DataFrame({
"index": ['A', 'C', 'D', 'E', 'F'],
"x1": [1, 2, 2, 2, 3],
"x2": [1, 2, 1, 0, 1],
"y": [1, 1, -1, -1, -1]
})
test_data = pd.DataFrame({
"index": ['A', 'B', 'C', 'D', 'E', 'F', 'G'],
"x1": [1, 1, 2, 2, 2, 3, 3],
"x2": [1, 2, 2, 1, 0, 1, 0],
"y": [1, 1, 1, -1, -1, -1, -1]
})
model = OptimalHyperTreeModel(["x1", "x2"], "y", tree_depth=2, N_min=1, alpha=0.1, solver_name="cplex")
model.train(data)

print(model.predict(test_data))
```

### Todos
1. Use the solution from the previous depth tree as a "Warm Start" to speed up the time to solve the Mixed Integer Linear Programming (MILP); (Done √)
2. Use the solution from sklearn's CART to give a good initial solution (Done √);


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

pyoptree-1.0.1.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

pyoptree-1.0.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file pyoptree-1.0.1.tar.gz.

File metadata

  • Download URL: pyoptree-1.0.1.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for pyoptree-1.0.1.tar.gz
Algorithm Hash digest
SHA256 282a85c7e2d96f050882b0add75d5b9bb87b4f551832dc8f1100f07df377a168
MD5 29509a4167e3c2755610bc2ba1df616d
BLAKE2b-256 8c4333158ed04d25c08d9c07435e51aedd93a6dfd47ebfb73ec7f35810158e59

See more details on using hashes here.

File details

Details for the file pyoptree-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pyoptree-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.18.4 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.5

File hashes

Hashes for pyoptree-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 030833bd7d145827c481297fd3f4d652f945b3f00a8d267a9ab92fa2b31a4817
MD5 59954f0cffb57ca90f415a00e63e3a6c
BLAKE2b-256 5723b485cca5d6cd58abaa8fd1d108880a6f15e015ec77a10e1a03c7d0640488

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