Decision tree (regression)

A decision tree (regression) is a type of model that uses a combination of rules. The collection of rules is represented by a tree-shaped graph (tree structure), which is easy to interpret. This page runs a regression of a decision tree and further visualizes the resulting tree.

from sklearn.tree import DecisionTreeRegressor
from sklearn.datasets import make_regression
from dtreeviz.trees import *

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from dtreeviz.trees import dtreeviz

Generate sample data for decision trees

X, y = make_regression(n_samples=100, n_features=2, random_state=777)
plt.figure(figsize=(10, 10))
plt.scatter(X[:, 0], X[:, 1], c=y)


Check how the regression tree branches.

tree = DecisionTreeRegressor(max_depth=3, random_state=117117)
model =, y)
viz = dtreeviz(tree, X, y, target_name="y")"./regression_tree.svg")

Visualize the branching of a regression tree

from IPython.display import SVG




(Comments will appear after approval)