The new TF Decision Forests library is really cool in Colab, and I’m trying to get it working in a Kaggle notebook. Please find below a link to a Kaggle notebook where I’ve successfully used the new Decision Forest library. However, there is an issue with the model_plotter (on bottom of the Kaggle Kernel).

Any suggestion on what can be done to plot the model as it worked without a problem in Google Colab? Thank you!


Thanks :slight_smile: (for the positive feedback and alert).

TF-DF uses D3 for plotting. And it seems (looking at the console of the web browser development tool) that Jupiter does not support the way TF-DF import D3.

A solution, is to re-import D3 in a Jupyer notebook cell:

    paths: {
        d3: ""

require(["d3"], function(d3) {
    window.d3 = d3;

then, the following like should work fine

tfdf.model_plotter.plot_model_in_colab(model, tree_idx=0, max_depth=3)

Note that you might have to clear the cell output and reload the webpage.

Alternatively, or if you don’t have a Jupiter or a Colab nodebook, the model plot can be exported to an html and visualized separably. For example:

with open("/tmp/model.html", "w") as f:
    f.write(tfdf.model_plotter.plot_model(model, tree_idx=0, max_depth=3))

# Then, open "/tmp/model.html" in any web browser.

Thank you Mathieu! This solves the problem.