alibi.utils.mapping module

alibi.utils.mapping.num_to_ord(data, dist)[source]

Transform numerical values into categories using the map calculated under the fit method.

Parameters
  • data (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

ndarray

Returns

Numpy array with transformed numerical data into categories.

alibi.utils.mapping.ohe_to_ord(X_ohe, cat_vars_ohe)[source]

Convert one-hot encoded variables to ordinal encodings.

Parameters
  • X_ohe (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

Tuple[ndarray, dict]

Returns

Ordinal equivalent of one-hot encoded data and dict with categorical columns and number of categories.

alibi.utils.mapping.ohe_to_ord_shape(shape, cat_vars, is_ohe=False)[source]

Infer shape of instance if the categorical variables have ordinal instead of on-hot encoding.

Parameters
  • shape (tuple) – Instance shape, starting with batch dimension.

  • cat_vars (Dict[int, int]) – Dict with as keys the categorical columns and as values the number of categories per categorical variable.

  • is_ohe (bool) – Whether instance is OHE.

Return type

tuple

Returns

Tuple with shape of instance with ordinal encoding of categorical variables.

alibi.utils.mapping.ord_to_num(data, dist)[source]

Transform categorical into numerical values using a mapping.

Parameters
  • data (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

ndarray

Returns

Numpy array with transformed categorical data into numerical values.

alibi.utils.mapping.ord_to_ohe(X_ord, cat_vars_ord)[source]

Convert ordinal to one-hot encoded variables.

Parameters
  • X_ord (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

Tuple[ndarray, dict]

Returns

One-hot equivalent of ordinal encoded data and dict with categorical columns and number of categories.