explainerdashboard icon indicating copy to clipboard operation
explainerdashboard copied to clipboard

Autogluon and explainerdashboard integration

Open apavlo89 opened this issue 2 years ago • 4 comments

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

apavlo89 avatar Jun 14 '23 15:06 apavlo89

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

oegedijk avatar Jun 28 '23 08:06 oegedijk

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

AlexanderZender avatar Jul 07 '23 10:07 AlexanderZender

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

oegedijk avatar Jul 08 '23 20:07 oegedijk

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.

AlexanderZender avatar Jul 09 '23 10:07 AlexanderZender