> ## Documentation Index
> Fetch the complete documentation index at: https://nixtlaverse.nixtla.io/llms.txt
> Use this file to discover all available pages before exploring further.

> Conformal prediction intervals and transfer conformal methods

# Conformal Prediction

##

### `PredictionIntervals`

```python theme={null}
PredictionIntervals(n_windows=2, h=1, method='conformal_distribution', scale_estimator=None)
```

Class for storing prediction intervals metadata information.

### `TransferConformal`

```python theme={null}
TransferConformal(method='recalibrate', dre_estimator='logistic', weights=None, n_windows=None, step_size=None, cv=5, clip_quantile=0.99)
```

Predict-time configuration for transfer conformal prediction.

Pass to `MLForecast.predict(transfer_conformal=...)` instead of the
removed flat kwargs `transfer_conformal_method`, `covariate_shift_weights`,
and `dre_estimator`.  A plain string is shorthand for
`TransferConformal(method=<str>)`.

#### `TransferConformal.validate`

```python theme={null}
validate(pi)
```

Cross-validate against the fitted PredictionIntervals config.

### `estimate_density_ratio`

```python theme={null}
estimate_density_ratio(source_features, target_features, estimator='logistic', cv=5, clip_quantile=0.99, return_target_weights=False)
```

Estimate w(x) = p\_target(x) / p\_source(x) for source domain points.

Trains a binary classifier (source=0, target=1) on StandardScaler-
normalised features and returns the odds ratio p(1|x) / p(0|x) for
each source point.

**Parameters:**

| Name                    | Type                                                        | Description                                                                                                                                                                                                                                    | Default                 |
| ----------------------- | ----------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------- |
| `source_features`       | <code>[ndarray](#numpy.ndarray)</code>                      | Feature matrix for source-domain calibration points, shape (n\_source, n\_features).                                                                                                                                                           | *required*              |
| `target_features`       | <code>[ndarray](#numpy.ndarray)</code>                      | Feature matrix for target-domain points, shape (n\_target, n\_features).                                                                                                                                                                       | *required*              |
| `estimator`             | <code>[str](#str)</code>                                    | `"logistic"` (default) or `"gradient_boosting"`.                                                                                                                                                                                               | <code>'logistic'</code> |
| `cv`                    | <code>[int](#int)</code>                                    | Number of stratified K-fold splits for cross-fitting (`cv >= 2`). Source weights are computed from out-of-fold predictions, reducing overfitting from in-sample scoring. `cv=0` or `cv=1` uses the original in-sample behavior. Defaults to 5. | <code>5</code>          |
| `clip_quantile`         | <code>[Optional](#typing.Optional)\[[float](#float)]</code> | Clip source weights above this quantile of the computed weights to prevent extreme values. `None` disables clipping. Defaults to 0.99.                                                                                                         | <code>0.99</code>       |
| `return_target_weights` | <code>[bool](#bool)</code>                                  | If `True`, also return per-target-row weights (averaged across fold models when `cv >= 2`). Defaults to `False`.                                                                                                                               | <code>False</code>      |

**Returns:**

| Type                                                                                                                                           | Description                                                             |
| ---------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| <code>[Union](#typing.Union)\[[ndarray](#numpy.ndarray), [Tuple](#typing.Tuple)\[[ndarray](#numpy.ndarray), [ndarray](#numpy.ndarray)]]</code> | np.ndarray of shape (n\_source,) if `return_target_weights=False`, else |
| <code>[Union](#typing.Union)\[[ndarray](#numpy.ndarray), [Tuple](#typing.Tuple)\[[ndarray](#numpy.ndarray), [ndarray](#numpy.ndarray)]]</code> | a tuple `(source_weights, target_weights)` where target\_weights has    |
| <code>[Union](#typing.Union)\[[ndarray](#numpy.ndarray), [Tuple](#typing.Tuple)\[[ndarray](#numpy.ndarray), [ndarray](#numpy.ndarray)]]</code> | shape (n\_target,).                                                     |
