Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
img
Example-Classification_and_Regression.ipynb
Example-Classification_and_Regression_V2.0.ipynb
ReadMe.md
trees.py

ReadMe.md

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

import numpy as np
import matplotlib.pyplot as plt

# Download trees.py 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 = data.data
y = data.target

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

clf.fit(Xt,yt,verbose=2,feature_names=feature_names)  

Plot the decision tree

# Plot Tree that has been learned
plt.figure(figsize=(15,8))
clf.plotTree(show=True)

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.