# 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 √);
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 √);
Metadata
Release files for pyoptree 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyoptree-1.0.3.tar.gz | 14.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyoptree-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.3 kB
Release files / pyoptree-1.0.3.tar.gz
| Download URL | pyoptree-1.0.3.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cda9fab77ff204916451f941d674bed1646107ed160ad6c890a5e0f71059b8a3
|
|
BLAKE2b-256 checksum How to use checksums |
8812edd585dc1a0baa0729a62964d0b5dea6ec97b98a454475cf83dba8a9ca47
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / pyoptree-1.0.3-py3-none-any.whl
| Download URL | pyoptree-1.0.3-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e98b9d564da7c0dae9bc2065c2f1861d1dd84a5de142267ccf93a1f5431cc3a7
|
|
BLAKE2b-256 checksum How to use checksums |
17cad2513a5ff2139fcec22b0a8e7d18a58083759769416096428b161cd9f213
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|