interpretml / interpret

Fit interpretable models. Explain blackbox machine learning.
https://interpret.ml/docs
MIT License
6.04k stars 714 forks source link

Visualising Decision Tree explainer gives a Cytoscape object which is not savable to my local machine #522

Open kaspersgit opened 1 month ago

kaspersgit commented 1 month ago

In contrast with the linear models and EBM which give a Plotly Figure back when running .visualise() on an explainer object, the decision tree (classifier and regressor) give back a Cytoscape object. The plotly figure is downloadable but for the Cytoscape object I have not figured it out.

Is this difference on purpose? Is there a way to download the decision tree explainer objects?

Code to show both objects:

import numpy as np
from sklearn.datasets import make_classification
from interpret.glassbox import ClassificationTree, ExplainableBoostingClassifier

# Generate fake classification data
X, y = make_classification(n_samples=1000, n_features=10, n_informative=3, n_redundant=2, random_state=42)

# Train an EBM model
ebm = ExplainableBoostingClassifier(random_state=42)
ebm.fit(X, y)

# Create a global explanation object
ebm_global_explanation = ebm.explain_global()

# Print the global explanation
print(ebm_global_explanation.visualize())

# Train an interpretable decision tree classifier
tree = ClassificationTree(random_state=42)
tree.fit(X, y)

# Create a global explanation object
tree_global_explanation = tree.explain_global()

# Print the global explanation
print(tree_global_explanation.visualize())
paulbkoch commented 1 month ago

Hi @kaspersgit -- @Harsha-Nori and @nopdive are the experts on this section of the code, but my limited understanding is that plotly was designed for X/Y plots, but not for directed graphs like a decision tree, so they used Cytoscape for that. I think the answer to your question about outputting them as text is that you can't, but I'll defer to Harsha and Sam on that one. You should be able to pickle them though I would think if you just wanted serialization.

kaspersgit commented 1 month ago

That limitation of plotly makes sense.

In my use case I was looking for a way to save it as a regular project png (or similar) image file.

I hope Harsha or Sam have some suggestion on how to do this, it would help a lot!