Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Decision Trees

Classification and Regression Tree

Requirement: All you need for this is Numpy and matplotlib** (Of course Python >=3.0)

See the Examples in Jupyter-Notebook for more details


import numpy as np
import matplotlib.pyplot as plt

# Download and keep in current directory or give a path (if you know how to)
from trees import ClassificationTree, RegressionTree

# For examples
from sklearn import datasets
from sklearn.model_selection import train_test_split

Iris Data

data = datasets.load_iris()
X =
y =

feature_names = data.feature_names #Optional
Xt,Xs, yt, ys = train_test_split(X,y,test_size=0.3)

Initiate the classifier and train it

clf = ClassificationTree()

# verbose 0 for no progress, 1 for short and 2 for detailed.
# feature_names is you know, else leave it or set it to None,yt,verbose=2,feature_names=feature_names)  

Plot the decision tree

# Plot Tree that has been learned

Visualizing the tree building while training

Iris Data (Classification)

Breast cancer Data (Classification)

Bostan House price Data (Regression)

Visualization of decision tree after fitting a model

Iris data: Decesion Tree (Option to show colored branch: Blue for True and Red for False)

Cancer data: Decesion Tree (Or just show all branches as blue with direction to indicate True and False branch)

Boston data: Decesion Tree

Visualizing the progress of tree building while training

Tree building for Cancer Data (Classification)

Detailed view

Short view

You can’t perform that action at this time.