alibi_detect.utils.mapping module¶
-
alibi_detect.utils.mapping.
num2ord
(data, dist)[source]¶ Transform numerical values into categories using the map calculated under the fit method.
- Parameters
data (numpy.ndarray) – Numpy array with the numerical data.
dist (
dict
) – Dict with as keys the categorical variables and as values the numerical value for each category.
- Return type
numpy.ndarray
- Returns
Numpy array with transformed numerical data into categories.
-
alibi_detect.utils.mapping.
ohe2ord
(X_ohe, cat_vars_ohe)[source]¶ Convert one-hot encoded variables to ordinal encodings.
- Parameters
X_ohe (numpy.ndarray) – Data with mixture of one-hot encoded and numerical variables.
cat_vars_ohe (
dict
) – Dict with as keys the first column index for each one-hot encoded categorical variable and as values the number of categories per categorical variable.
- Return type
- Returns
Ordinal equivalent of one-hot encoded data and dict with categorical columns and number of categories.
-
alibi_detect.utils.mapping.
ohe2ord_shape
(shape, cat_vars=None, is_ohe=False)[source]¶ Infer shape of instance if the categorical variables have ordinal instead of on-hot encoding.
- Parameters
- Return type
- Returns
Tuple with shape of instance with ordinal encoding of categorical variables.
-
alibi_detect.utils.mapping.
ord2num
(data, dist)[source]¶ Transform categorical into numerical values using a mapping.
- Parameters
data (numpy.ndarray) – Numpy array with the categorical data.
dist (
dict
) – Dict with as keys the categorical variables and as values the numerical value for each category.
- Return type
numpy.ndarray
- Returns
Numpy array with transformed categorical data into numerical values.
-
alibi_detect.utils.mapping.
ord2ohe
(X_ord, cat_vars_ord)[source]¶ Convert ordinal to one-hot encoded variables.
- Parameters
X_ord (numpy.ndarray) – Data with mixture of ordinal encoded and numerical variables.
cat_vars_ord (
dict
) – Dict with as keys the categorical columns and as values the number of categories per categorical variable.
- Return type
- Returns
One-hot equivalent of ordinal encoded data and dict with categorical columns and number of categories.