rr-caretlime

Lime package not able to get predictions for CaretStack


I built a Caret ensemble model by stacking models together.

The model ran successfully and I got encouraging results.

The challenge came when I tried to use Lime to interpret the black box predictions. I got an error saying "The class of model must have a model_type method"

The only time I encountered such error was when using Lime in H20. Subsequently, the guys behind Lime have released an update that supports H20 in Lime.

Does anyone know if any work has been done to include CaretStack for use with Lime? Or know of a workaround to solve this issue.


Solution

  • According to the Lime documentation, these are the supported models

    Out of the box, lime supports the following model objects:

    1. train from caret

    2. WrappedModel from mlr

    3. xgb.Booster from xgboost

    4. H2OModel from h2o

    5. keras.engine.training.Model from keras

    6. lda from MASS (used for low-dependency examples)

    If your model is not one of the above you'll need to implement support yourself. If the model has a predict interface mimicking that of predict.train() from caret, it will be enough to wrap your model in as_classifier()/as_regressor() to gain support.

    Otherwise you'll need need to implement a predict_model() method and potentially a model_type() method (if the latter is omitted the model should be wrapped in as_classifier()/as_regressor(), everytime it is used in lime()).

    Solution to your question:

    For your case, CaretStack has a predict interface mimicking that of predict.train(), so wrapping your model in as_classifier() or as_regressor() should suffice