oegedijk / explainerdashboard

Quickly build Explainable AI dashboards that show the inner workings of so-called "blackbox" machine learning models.
http://explainerdashboard.readthedocs.io
MIT License
2.31k stars 332 forks source link

Autogluon and explainerdashboard integration #270

Open apavlo89 opened 1 year ago

apavlo89 commented 1 year ago

Is there a way to load autogluon models into explainer dashboard?

oegedijk commented 1 year ago

I have never tried! As long as they are sklearn compatible and work with shap it should work I guess!

AlexanderZender commented 1 year ago

If this is still of interest, I managed to make AutoGluon work with explainer dashboard. I used the most recent releases of both.

You need to wrap the model into a wrapper class that changes the predict_proba function, as the default result of Autogluon is different of what explainer dashboard expects:

  import numpy as np

  class AutoGluonWrapper:

      def __init__(self, model) -> None:
          self.__model = model

      def predict(self, x, **kwargs):
          self.__model.predict(x=x, **kwargs)

      def predict_proba(self, x, **kwargs):

          probabilities_raw = self.__model.predict_proba(x, **kwargs)
          probabilities = np.array(probabilities_raw)
          return probabilities

Then you can just call the dashboard using a training AutoGluon model:

dashboard = ExplainerDashboard(ClassifierExplainer(AutoGluonWrapper(model), X_test, y_test))
oegedijk commented 1 year ago

wait, so the issue is that predict_proba doesn't return an np.ndarray by default? That should be easy enough to wrap or detect inside the library

AlexanderZender commented 1 year ago

Indeed, that is the issue with this AutoML, most AutoML actually work out of the box or with a simple wrapper class similar to the one I posted above. In case a wrapper is needed, it is because the predict_proba returns something unexpected.