Skip to content

Mixed continuous and categorical features in the AnchorTabular explainers (my dataset doesn't contain NaNs) #990

@TopCoder2K

Description

@TopCoder2K

Hi there!

I've seen #364 in which it's said "We may extend the types of data handled by the alibi explainers in the future (e.g. working on pandas dataframes) but this is not an immediate priority as there are several potential complications with this". Has there been any progress on this in 2.5 years?

I've tried to run AnchorTabular with the CatBoostRegressor trained on a dataset containing both continuous and categorical features:

from alibi.utils import gen_category_map
from alibi.explainers import AnchorTabular

category_map = gen_category_map(
    X_train, categorical_columns=categorical_features
)
AnchorTabular(
    lambda x: cb_model.predict(x), X_train.columns, categorical_names=category_map
)

but got

CatBoostError: 'data' is numpy array of floating point numerical type, it means no categorical features, but 'cat_features' parameter specifies nonzero number of categorical features

The above exception was the direct cause of the following exception:

PredictorCallError                        Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/alibi/explainers/anchors/anchor_tabular.py](https://localhost:8080/#) in _transform_predictor(self, predictor)
   1010             msg = f"Predictor failed to be called on {type(x)} of shape {x.shape} and dtype {x.dtype}. " \
   1011                   f"Check that the parameter `feature_names` is correctly specified."
-> 1012             raise PredictorCallError(msg) from e
   1013 
   1014         if not isinstance(prediction, np.ndarray):

PredictorCallError: Predictor failed to be called on <class 'numpy.ndarray'> of shape (1, 11) and dtype float32. Check that the parameter `feature_names` is correctly specified.

because the explainer gives

[[0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]

Is there any way to supply categorical and continuous values simultaneously?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions