> ## 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.

# Conditional randomization tests

> Conditional Randomization Test (CRT) using TabPFN.

## Installation

```bash theme={null}
pip install tabpfn-extensions
```

## `tabpfn_crt`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/crt.py#L30)

Conditional Randomization Test (CRT) using TabPFN.

This function tests whether one or more features contain predictive
information about the target variable y beyond the remaining covariates.

For each feature X\_j, the CRT compares:

Observed statistic:
Mean log predictive density of y given the observed `X`.

Null statistic:
Same quantity when X\_j is replaced by samples drawn from
p(X\_j | X\_-j).

```python theme={null}
tabpfn_crt(
    X: Any,
    y: Any,
    j: int | str | Sequence[int | str],
    *,
    B: int = 200,
    alpha: float = 0.05,
    test_size: float = 0.2,
    seed: int = 0,
    device: str | None = None,
    K: int = 100,
    max_unique_cat: int = 10,
    model_version: ModelVersion = ModelVersion.V2,
    use_kv_cache: bool = True,
) -> dict[str, Any] | dict[int | str, dict[str, Any]]
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `X` | `Any` | Required | — |
| `y` | `Any` | Required | — |
| `j` | `int \| str \| Sequence[int \| str]` | Required | — |
| `B` | `int` | `200` | — |
| `alpha` | `float` | `0.05` | — |
| `test_size` | `float` | `0.2` | — |
| `seed` | `int` | `0` | — |
| `device` | `str \| None` | `None` | — |
| `K` | `int` | `100` | — |
| `max_unique_cat` | `int` | `10` | — |
| `model_version` | `ModelVersion` | `ModelVersion.V2` | — |
| `use_kv_cache` | `bool` | `True` | — |

**Efficiency**

The predictive model p(y | `X`) is fit ONLY ONCE and reused across all
tested features. Each feature requires fitting only the conditional
model p(X\_j | X\_-j).

Supports:
• single feature testing
• batch feature testing

**Returns**

| Type | Description |
| - | - |
| `Single feature → result dict` | |
| `Multiple features → dict[feature → result dict]` | |

***

## `coerce_X_y_to_numpy`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/utils.py#L13)

Convert `X` and y to numpy arrays while preserving feature names if `X` is a DataFrame.

```python theme={null}
coerce_X_y_to_numpy(
    X: Any,
    y: Any,
) -> tuple[np.ndarray, np.ndarray, Sequence[str] | None]
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `X` | `Any` | Required | — |
| `y` | `Any` | Required | — |

**Returns**

| Type | Description |
| - | - |
| `tuple[np.ndarray, np.ndarray, Sequence[str] \| None]` | — |

***

## `is_categorical`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/utils.py#L62)

Heuristic to determine whether a variable should be treated as categorical.

```python theme={null}
is_categorical(
    arr,
    max_unique = 10,
)
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `arr` | `array - like` | Required | Input array. |
| `max_unique` | `int` | `10` | Maximum number of unique values for categorical treatment. |

**Returns**

| Type | Description |
| - | - |
| `bool` | `True` if categorical, `False` otherwise. |

***

## `logp_from_full_output`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/utils.py#L82)

Extract log predictive density from TabPFN 'full' prediction output.

```python theme={null}
logp_from_full_output(
    full_out,
    y_np,
)
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `full_out` | `dict` | Required | Output from TabPFN predict(..., output\_type="full"). |
| `y_np` | `array - like` | Required | Ground-truth targets. |

**Returns**

| Type | Description |
| - | - |
| `np.ndarray` | Log predictive density for each observation. |

***

## `logp_from_proba`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/utils.py#L110)

Compute log p(`y_true` | x) from class probabilities.

probs: shape (n, C)
`y_true`: shape (n,)
classes: model.classes\_

```python theme={null}
logp_from_proba(
    probs,
    y_true,
    classes,
)
```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `probs` | — | Required | — |
| `y_true` | — | Required | — |
| `classes` | — | Required | — |

***

## `resolve_feature_index`

[ View source ](https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/utils.py#L34)

Resolve feature identifier j into integer index and optional name.

```python theme={null}
resolve_feature_index(
    j: FeatureSpec,
    feature_names: Sequence[str] | None,
    n_features: int,
) -> tuple[int, str | None]
```

> [accordion] Type aliases
>
> ```python theme={null}
> FeatureSpec = int | str
> ```

**Parameters**

| Parameter | Type | Default | Description |
| - | - | - | - |
| `j` | `FeatureSpec` | Required | — |
| `feature_names` | `Sequence[str] \| None` | Required | — |
| `n_features` | `int` | Required | — |

**Returns**

| Type | Description |
| - | - |
| `tuple[int, str \| None]` | — |


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