Skip to main content

Python Implementation of Bertsimas's paper Optimal Classification Trees.

Project description

# pyoptree
Python Optimal Tree

### Dependencies
#### Python dependencies (through pip)
1. numpy
2. pandas
3. pyomo

#### Solver dependencies
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 viariable (i.e. command `cplex` or `gurobi` can be run on terminal).

### Example
```python
import pandas as pd
from optree.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. Implement "Warm Start" to speed up the time to solve the Mixed Integer Linear Programming (MILP);
2. Implement heuristics such as Generic Algorithms to approximate the optimal solution rapidly (but may be loss of accuracy);


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

Uploaded Source

Built Distribution

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

pyoptree-0.1.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyoptree-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 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-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f460a70f6d1070a0313dc900102d623ae695df752e1ab66ce917fe42e8dd8add
MD5 ec4543fc92fa02fc2579a6a7afc05fff
BLAKE2b-256 3645d8bc6a160a0afd479f98a47b0c1cf1d47d98193044330f9a281e79988fb2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoptree-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.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-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 16d831c9c1ae46ef6ace7c953d41a3f209629055aea0623fc3c5a4aa31bcd976
MD5 dbc87d125e26e4ed1ffd61c96d4fb39b
BLAKE2b-256 0faac3dd834db974b92eb453f07acf7e3f949a428d67dd9c5d9a965a7c487c2d

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