Search code examples
pythongraphvizlightgbmdtreeviz

Dtreeviz NameError


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.


Solution

  • 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)