Skip to content

a python interface to OC1 and other oblique decision tree implementations

License

Notifications You must be signed in to change notification settings

AndriyMulyar/sklearn-oblique-tree

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌳 Oblique Decision Trees in Python

A python interface to oblique decision tree implementations:

Installation (Python 3)

First install numpy with:

pip install numpy

then run:

pip install git+https://github.com/AndriyMulyar/sklearn-oblique-tree

Use

Trees can be induced with the normal scikit-learn classifier api. For instance:

from sklearn.datasets import load_iris, load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn_oblique_tree.oblique import ObliqueTree

random_state = 2

#see Murthy, et all for details.
#For oblique with consideration of axis parallel
#tree = ObliqueTree(splitter="oc1, axis_parallel", number_of_restarts=20, max_perturbations=5, random_state=random_state)
#
#For multivariate CART select 'cart' splitter
#tree = ObliqueTree(splitter="cart", number_of_restarts=20, max_perturbations=5, random_state=random_state)

#consider only oblique splits
tree = ObliqueTree(splitter="oc1", number_of_restarts=20, max_perturbations=5, random_state=random_state)

X_train, X_test, y_train, y_test = train_test_split(*load_iris(return_X_y=True), test_size=.4, random_state=random_state)

tree.fit(X_train, y_train)

predictions = tree.predict(X_test)


print("Iris Accuracy:",accuracy_score(y_test, predictions))

Acknowledgements

VCU Imbalanced Learning and Data Stream Mining Laboratory alt text

Original (unmodified) OC1 Source Code

https://github.com/AndriyMulyar/sklearn-oblique-tree/tree/412d502c04d66046388e469a329d8bcf195bf34b/oc1_implementation