# alibi\_detect.cd.preprocess

## Functions

### `classifier_uncertainty`

```python
classifier_uncertainty(x: Union[numpy.ndarray, list], model_fn: Callable, preds_type: str = 'probs', uncertainty_type: str = 'entropy', margin_width: float = 0.1) -> numpy.ndarray
```

Evaluate model\_fn on x and transform predictions to prediction uncertainties.

| Name               | Type                         | Default     | Description                                                                                                                                                                                                |
| ------------------ | ---------------------------- | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `x`                | `Union[numpy.ndarray, list]` |             | Batch of instances.                                                                                                                                                                                        |
| `model_fn`         | `Callable`                   |             | Function that evaluates a classification model on x in a single call (contains batching logic if necessary).                                                                                               |
| `preds_type`       | `str`                        | `'probs'`   | Type of prediction output by the model. Options are 'probs' (in \[0,1]) or 'logits' (in \[-inf,inf]).                                                                                                      |
| `uncertainty_type` | `str`                        | `'entropy'` | Method for determining the model's uncertainty for a given instance. Options are 'entropy' or 'margin'.                                                                                                    |
| `margin_width`     | `float`                      | `0.1`       | Width of the margin if uncertainty\_type = 'margin'. The model is considered uncertain on an instance if the highest two class probabilities it assigns to the instance differ by less than margin\_width. |

**Returns**

* Type: `numpy.ndarray`

### `regressor_uncertainty`

```python
regressor_uncertainty(x: Union[numpy.ndarray, list], model_fn: Callable, uncertainty_type: str = 'mc_dropout', n_evals: int = 25) -> numpy.ndarray
```

Evaluate model\_fn on x and transform predictions to prediction uncertainties.

| Name               | Type                         | Default        | Description                                                                                                                                                                                                                  |
| ------------------ | ---------------------------- | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `x`                | `Union[numpy.ndarray, list]` |                | Batch of instances.                                                                                                                                                                                                          |
| `model_fn`         | `Callable`                   |                | Function that evaluates a regression model on x in a single call (contains batching logic if necessary).                                                                                                                     |
| `uncertainty_type` | `str`                        | `'mc_dropout'` | Method for determining the model's uncertainty for a given instance. Options are 'mc\_dropout' or 'ensemble'. The former should output a scalar per instance. The latter should output a vector of predictions per instance. |
| `n_evals`          | `int`                        | `25`           | The number of times to evaluate the model under different dropout configurations. Only relavent when using the 'mc\_dropout' uncertainty type.                                                                               |

**Returns**

* Type: `numpy.ndarray`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.seldon.ai/alibi-detect/api-reference/cd/preprocess.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
