1

I installed dtreebiz and wanted to make a three plot. I did exactly what example codes say as below, but keep getting "NameError: name 'dtreeviz' is not defined".

from dtreeviz.trees import *

viz = dtreeviz(lgbm,
               x_data = df_X_train,
               y_data = df_y_train,
               target_name = TARGET,
               feature_names = df_X_train.columns.tolist(),
               tree_index = 0)

viz

I checked the version using pip show dtreeviz and confirmed version 2.1.3 is installed. I am using Spyder mostly but I also tried the same thing with Jupyter Notebook and got the same error.

Tommy
  • 47
  • 4

2 Answers2

1

There was some compatibility issues from version 1 to 2. I would suggest to start using the new 2.0 API :)

For the old API, you could try:

from dtreeviz import *
viz = dtreeviz(lgbm,
               x_data = df_X_train,
               y_data = df_y_train,
               target_name = TARGET,
               feature_names = df_X_train.columns.tolist(),
               tree_index = 0)
0

You need to add

import dtreeviz

to your code (see the Quick Start in dtreeviz github page). Importing all the symbols from dtreeviz.trees, like you're doing with

from dtreeviz.trees import *

imports the symbols in the trees module only.

joao
  • 2,220
  • 2
  • 11
  • 15
  • Thank you very much, but this time I got the error: TypeError: 'module' object is not callable. I also tried "from dtreeviz.trees import dtreeviz" and this case got ImportError: cannot import name 'dtreeviz' from 'dtreeviz.trees' (c:\program files\python39\lib\site-packages\dtreeviz\trees.py) – Tommy Feb 04 '23 at 16:52