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

<div className="python-reference-heading">
  <h2 id="pval-crt-crt-tabpfn-crt">
    `tabpfn_crt`
  </h2>

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

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**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="pval-crt-crt-tabpfn-crt--x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">Any</code> | Required | — |
  | <span id="pval-crt-crt-tabpfn-crt--y" /><code className="python-reference-parameter">y</code> | <code className="python-reference-type">Any</code> | Required | — |
  | <span id="pval-crt-crt-tabpfn-crt--j" /><code className="python-reference-parameter">j</code> | <code className="python-reference-type">int \| str \| Sequence\[int \| str]</code> | Required | — |
  | <span id="pval-crt-crt-tabpfn-crt--b" /><code className="python-reference-parameter">B</code> | <code className="python-reference-type">int</code> | `200` | — |
  | <span id="pval-crt-crt-tabpfn-crt--alpha" /><code className="python-reference-parameter">alpha</code> | <code className="python-reference-type">float</code> | `0.05` | — |
  | <span id="pval-crt-crt-tabpfn-crt--test-size" /><code className="python-reference-parameter">test\_<wbr />size</code> | <code className="python-reference-type">float</code> | `0.2` | — |
  | <span id="pval-crt-crt-tabpfn-crt--seed" /><code className="python-reference-parameter">seed</code> | <code className="python-reference-type">int</code> | `0` | — |
  | <span id="pval-crt-crt-tabpfn-crt--device" /><code className="python-reference-parameter">device</code> | <code className="python-reference-type">str \| None</code> | `None` | — |
  | <span id="pval-crt-crt-tabpfn-crt--k" /><code className="python-reference-parameter">K</code> | <code className="python-reference-type">int</code> | `100` | — |
  | <span id="pval-crt-crt-tabpfn-crt--max-unique-cat" /><code className="python-reference-parameter">max\_<wbr />unique\_<wbr />cat</code> | <code className="python-reference-type">int</code> | `10` | — |
  | <span id="pval-crt-crt-tabpfn-crt--model-version" /><code className="python-reference-parameter">model\_<wbr />version</code> | <code className="python-reference-type"><a href="/api-reference/python/tabpfn/model-versions#modelversion">Model<wbr />Version</a></code> | `ModelVersion.V2` | — |
  | <span id="pval-crt-crt-tabpfn-crt--use-kv-cache" /><code className="python-reference-parameter">use\_<wbr />kv\_<wbr />cache</code> | <code className="python-reference-type">bool</code> | `True` | — |
</div>

**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**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">Single feature → result dict</code> | |
  | <code className="python-reference-type">Multiple features → dict\[feature → result dict]</code> | |
</div>

***

<div className="python-reference-heading">
  <h2 id="pval-crt-utils-coerce-x-y-to-numpy">
    `coerce_X_y_to_numpy`
  </h2>

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

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**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="pval-crt-utils-coerce-x-y-to-numpy--x" /><code className="python-reference-parameter">X</code> | <code className="python-reference-type">Any</code> | Required | — |
  | <span id="pval-crt-utils-coerce-x-y-to-numpy--y" /><code className="python-reference-parameter">y</code> | <code className="python-reference-type">Any</code> | Required | — |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">tuple\[<a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a>, <a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a>, Sequence\[str] \| None]</code> | — |
</div>

***

<div className="python-reference-heading">
  <h2 id="pval-crt-utils-is-categorical">
    `is_categorical`
  </h2>

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

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

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

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="pval-crt-utils-is-categorical--arr" /><code className="python-reference-parameter">arr</code> | <code className="python-reference-type">array - like</code> | Required | Input array. |
  | <span id="pval-crt-utils-is-categorical--max-unique" /><code className="python-reference-parameter">max\_<wbr />unique</code> | <code className="python-reference-type">int</code> | `10` | Maximum number of unique values for categorical treatment. |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">bool</code> | `True` if categorical, `False` otherwise. |
</div>

***

<div className="python-reference-heading">
  <h2 id="pval-crt-utils-logp-from-full-output">
    `logp_from_full_output`
  </h2>

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

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

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

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="pval-crt-utils-logp-from-full-output--full-out" /><code className="python-reference-parameter">full\_<wbr />out</code> | <code className="python-reference-type">dict</code> | Required | Output from TabPFN predict(..., output\_type="full"). |
  | <span id="pval-crt-utils-logp-from-full-output--y-np" /><code className="python-reference-parameter">y\_<wbr />np</code> | <code className="python-reference-type">array - like</code> | Required | Ground-truth targets. |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type"><a href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html">np.ndarray</a></code> | Log predictive density for each observation. |
</div>

***

<div className="python-reference-heading">
  <h2 id="pval-crt-utils-logp-from-proba">
    `logp_from_proba`
  </h2>

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

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**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="pval-crt-utils-logp-from-proba--probs" /><code className="python-reference-parameter">probs</code> | — | Required | — |
  | <span id="pval-crt-utils-logp-from-proba--y-true" /><code className="python-reference-parameter">y\_<wbr />true</code> | — | Required | — |
  | <span id="pval-crt-utils-logp-from-proba--classes" /><code className="python-reference-parameter">classes</code> | — | Required | — |
</div>

***

<div className="python-reference-heading">
  <h2 id="pval-crt-utils-resolve-feature-index">
    `resolve_feature_index`
  </h2>

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

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 title="Type aliases">
  ```python theme={null}
  FeatureSpec = int | str
  ```
</Accordion>

**Parameters**

<div className="python-reference-table">
  | Parameter | Type | Default | Description |
  | - | - | - | - |
  | <span id="pval-crt-utils-resolve-feature-index--j" /><code className="python-reference-parameter">j</code> | <code className="python-reference-type"><a href="https://github.com/PriorLabs/tabpfn-extensions/blob/840c15a1848a986b39c85bc17efc61e0e377f983/src/tabpfn_extensions/pval_crt/utils.py#L10">Feature<wbr />Spec</a></code> | Required | — |
  | <span id="pval-crt-utils-resolve-feature-index--feature-names" /><code className="python-reference-parameter">feature\_<wbr />names</code> | <code className="python-reference-type">Sequence\[str] \| None</code> | Required | — |
  | <span id="pval-crt-utils-resolve-feature-index--n-features" /><code className="python-reference-parameter">n\_<wbr />features</code> | <code className="python-reference-type">int</code> | Required | — |
</div>

**Returns**

<div className="python-reference-table python-reference-returns">
  | Type | Description |
  | - | - |
  | <code className="python-reference-type">tuple\[int, str \| None]</code> | — |
</div>


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