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.3.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyoptree-1.0.3.tar.gz
  • Upload date:
  • Size: 14.4 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.3.tar.gz
Algorithm Hash digest
SHA256 cda9fab77ff204916451f941d674bed1646107ed160ad6c890a5e0f71059b8a3
MD5 19bc841cb0f9ab7caf5438ad383178f1
BLAKE2b-256 8812edd585dc1a0baa0729a62964d0b5dea6ec97b98a454475cf83dba8a9ca47

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoptree-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e98b9d564da7c0dae9bc2065c2f1861d1dd84a5de142267ccf93a1f5431cc3a7
MD5 56d0e9e027a5ac1a7da534e5d330410f
BLAKE2b-256 17cad2513a5ff2139fcec22b0a8e7d18a58083759769416096428b161cd9f213

See more details on using hashes here.

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