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

> ## Agent Instructions
> TabPFN-3 and later versions support up to 1,000,000 rows, subject to feature count and checkpoint/API limits.
> For large datasets, use per-estimator subsampling, e.g. inference_config={"SUBSAMPLE_SAMPLES": 100_000}, in TabPFNClassifier or TabPFNRegressor from tabpfn or tabpfn_client.
> Pass raw pandas DataFrames to fit and predict. Categorical strings/categories, raw text, and missing feature values are handled automatically; no manual integer/one-hot encoding, imputation, scaling, or outlier removal is needed.

# Anomaly detection

> Calculate outlier scores as the log of the arithmetic mean (AM) of the densities across the permutations used to approximate the chain rule.

<Info>
  Looking for usage documentation? Check out [Anomaly detection](/capabilities/anomaly-detection).
</Info>

<div className="python-reference-heading">
  <h2 id="unsupervised-unsupervised-tabpfnunsupervisedmodel-density">
    `TabPFNUnsupervisedModel.density_`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/unsupervised/unsupervised.py#L566" aria-label="View source for TabPFNUnsupervisedModel.density_"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Generate density predictions for a specific feature based on other features.

This internal method is used by the imputation and outlier detection algorithms
to model the conditional probability distribution of one feature given others.

```python theme={null}
TabPFNUnsupervisedModel.density_(
    X_predict: torch.Tensor,
    X_fit: torch.Tensor,
    conditional_idx: list[int],
    column_idx: int,
) -> tuple[Any, torch.Tensor, torch.Tensor]
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-density--x-predict" /><code className="python-reference-parameter">X\_<wbr />predict</code> | <code className="python-reference-type">torch.Tensor</code> | Required | Input data for which to make predictions |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-density--x-fit" /><code className="python-reference-parameter">X\_<wbr />fit</code> | <code className="python-reference-type">torch.Tensor</code> | Required | Training data to fit the model |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-density--conditional-idx" /><code className="python-reference-parameter">conditional\_<wbr />idx</code> | <code className="python-reference-type">list\[int]</code> | Required | Indices of features to condition on |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-density--column-idx" /><code className="python-reference-parameter">column\_<wbr />idx</code> | <code className="python-reference-type">int</code> | Required | Index of the feature to predict |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">tuple\[Any, torch.Tensor, torch.Tensor]</code> | tuple containing:<br />    - The fitted model (classifier or regressor)<br />    - The filtered features used for prediction<br />    - The target feature values to predict |
</div>

***

<div className="python-reference-heading">
  <h2 id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers">
    `TabPFNUnsupervisedModel.outliers`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/unsupervised/unsupervised.py#L840" aria-label="View source for TabPFNUnsupervisedModel.outliers"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Calculate outlier scores as the log of the arithmetic mean (AM) of the densities across the permutations used to approximate the chain rule.

The logsumexp trick is used to compute the log of the AM to address the risk of over- or underflow.

```python theme={null}
TabPFNUnsupervisedModel.outliers(
    X: torch.Tensor | np.ndarray | pd.DataFrame,
    n_permutations: int = 10,
) -> torch.Tensor
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers--x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">torch.Tensor \| <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a> \| <a href="https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html">pd.Data<wbr />Frame</a></code> | Required | Union\[torch.Tensor, [`np.ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html), [`pd.DataFrame`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.html)] Samples to calculate outlier scores for, shape (n\_samples, n\_features) |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers--n-permutations" /><code className="python-reference-parameter">n\_<wbr />permutations</code> | <code className="python-reference-type">int</code> | `10` | int, default=10 Number of permutations to use for more robust probability estimates. Higher values may produce more stable results but increase computation time. |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">torch.Tensor</code> | torch.Tensor:     Tensor of outlier scores as log(AM(densities)), (lower values indicate more likely outliers), shape (n\_samples,). |
</div>

**Raises**

`RuntimeError`

If the model initialization fails

`ValueError`

If the input data has incompatible dimensions

***

<div className="python-reference-heading">
  <h2 id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-pdf">
    `TabPFNUnsupervisedModel.outliers_pdf`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/unsupervised/unsupervised.py#L790" aria-label="View source for TabPFNUnsupervisedModel.outliers_pdf"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Calculate the log\_pdf from numerical features only.

This method filters out categorical features and only considers numerical features
for outlier detection.

```python theme={null}
TabPFNUnsupervisedModel.outliers_pdf(
    X: torch.Tensor,
    n_permutations: int = 10,
) -> torch.Tensor
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-pdf--x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">torch.Tensor</code> | Required | Input data tensor |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-pdf--n-permutations" /><code className="python-reference-parameter">n\_<wbr />permutations</code> | <code className="python-reference-type">int</code> | `10` | Number of permutations to use for the outlier calculation |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">torch.Tensor</code> | log\_pdf (lower values indicate more likely outliers). |
</div>

***

<div className="python-reference-heading">
  <h2 id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-pmf">
    `TabPFNUnsupervisedModel.outliers_pmf`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/unsupervised/unsupervised.py#L815" aria-label="View source for TabPFNUnsupervisedModel.outliers_pmf"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Calculate log\_pmf from categorical features only.

This method filters out numerical features and only considers categorical features
for outlier detection.

```python theme={null}
TabPFNUnsupervisedModel.outliers_pmf(
    X: torch.Tensor,
    n_permutations: int = 10,
) -> torch.Tensor
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-pmf--x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">torch.Tensor</code> | Required | Input data tensor |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-pmf--n-permutations" /><code className="python-reference-parameter">n\_<wbr />permutations</code> | <code className="python-reference-type">int</code> | `10` | Number of permutations to use for the outlier calculation |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">torch.Tensor</code> | Tensor of outlier scores (lower values indicate more likely outliers) |
</div>

***

<div className="python-reference-heading">
  <h2 id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-single-permutation">
    `TabPFNUnsupervisedModel.outliers_single_permutation_`
  </h2>

  <a className="python-reference-source" href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/unsupervised/unsupervised.py#L721" aria-label="View source for TabPFNUnsupervisedModel.outliers_single_permutation_"><span aria-hidden="true">\</></span> View source <span aria-hidden="true">↗</span></a>
</div>

Compute the chain-rule log-density / log-probability of each row under one permutation.

```python theme={null}
TabPFNUnsupervisedModel.outliers_single_permutation_(
    X: torch.tensor,
    feature_permutation: list[int] | tuple[int],
) -> torch.tensor
```

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-single-permutation--x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">torch.tensor</code> | Required | — |
  | <span id="unsupervised-unsupervised-tabpfnunsupervisedmodel-outliers-single-permutation--feature-permutation" /><code className="python-reference-parameter">feature\_<wbr />permutation</code> | <code className="python-reference-type">list\[int] \| tuple\[int]</code> | Required | — |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">torch.tensor</code> | — |
</div>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.