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 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);
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 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
Release history Release notifications | RSS feed
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.1.tar.gz
(4.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyoptree-0.1.1.tar.gz.
File metadata
- Download URL: pyoptree-0.1.1.tar.gz
- Upload date:
- Size: 4.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12f05a7b2ed2d9ca612406d36d0eec4eb1761c89d4671835e75e474d1a4b9cbc
|
|
| MD5 |
457ae0035d4f41a6cce8e9fd64c17029
|
|
| BLAKE2b-256 |
d4bfa84be9e14ed42d9468166e3d45b3ef25bfc828468d1cb43a773b7d105e5b
|
File details
Details for the file pyoptree-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pyoptree-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08939a1404a28ab43846ead6f7d0ed8d5fb92f6367dfd0ecd0edef7c8c9e0052
|
|
| MD5 |
23aa0ab3af28c45e1d64afbf4d233131
|
|
| BLAKE2b-256 |
eb0f721292b2259fe5ce55bc31c7d8dcf3dce0c96cc796b1aa36ded369058be4
|