Dtreeviz Utility for Google Collab

I am having issues using the dtreeviz utility from lesson 9.

It does not work despite including the updated library with

!pip install -Uqq waterfallcharts treeinterpreter dtreeviz

?

Running

dtreeviz(m,xs.iloc[samp_idx],y.iloc[samp_idx],xs.columns,"input",fontname='DejaVu Sans',scale = 1.6,label_fontsize=10,orientation='LR')

throws the following error:

NameError: name 'dtreeviz' is not defined

Help is appreciated.

-Simon

Did you try to follow these install steps: GitHub - parrt/dtreeviz: A python library for decision tree visualization and model interpretation.

Thank you for the recommendation, @miwojc. I am using Google Collab, so this prompted me to look up the installation guide for that IDE. This notebook provided a solution:

import sys

if 'google.colab' in sys.modules:
  !pip install -q dtreeviz

import sys
import os
# add library module to PYTHONPATH
sys.path.append(f"{os.getcwd()}/../")

from sklearn.datasets import *
from dtreeviz.trees import *
from IPython.display import Image, display_svg, SVG
1 Like

this is the solution for kaggle notebook
import dtreeviz
samp_idx = np.random.permutation(len(y))[:500]
viz_model=dtreeviz.model(m,
X_train=xs.iloc[samp_idx],
y_train=y.iloc[samp_idx],
feature_names=xs.columns,
target_name=dep_var)

viz_model.view(fontname=‘DejaVu Sans’, scale=1.6, label_fontsize=10,
orientation=‘LR’)

2 Likes

Thanks! This worked for me