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

# Custom metrics

> Score a session with your own metric: a cost per error, a threshold, or a competition's formula.

When no [built-in metric](https://docs.priorlabs.ai/autofit/frame-a-task/metrics.md) matches how your predictions are judged, write the metric as a Python file. Autofit scores every experiment and every ensemble with it.

## Ask Claude to write it

At the **Use** question, choose **Something else** and describe the measure: what each kind of mistake costs, the threshold, which class is "yes". Claude writes `<name>_metric.py` next to your data, checks it, and shows its `score` function in the setup summary.

From a shell, pass the file instead of `--metric`:

```bash theme={null}
autofit start churn.csv --target churn --metric-file churn_metric.py
```

## The file

```python theme={null}
import numpy as np

NAME = "churn_cost"
GREATER_IS_BETTER = False
DESCRIPTION = "Cost per customer: a missed churner costs 5, a needless call 1; call above 30%."


def score(y_true, y_pred, y_proba, y_train=None):
    classes = list(np.unique(y_train))  # the order of y_proba's columns
    call = y_proba[:, classes.index(True)] > 0.3
    churned = np.asarray(y_true) == True  # noqa: E712
    return float(np.mean(5 * (churned & ~call) + 1 * (~churned & call)))
```

| Name | Required | Meaning |
| - | - | - |
| `NAME` | Yes | A short ID. Not a built-in metric's name. |
| `GREATER_IS_BETTER` | Yes | `True` if a higher score is better. |
| `DESCRIPTION` | Yes | One line, shown in the sidebar and the report. |
| `score` | Yes | Returns one number. |
| `OUTPUT_TYPE` | No | Regression only: `"mean"` (default) or `"median"`. Use `"median"` for metrics built on absolute errors. |
| `fit`, `transform` | No | A fitted step before scoring. See below. |

What `score` receives:

* `y_true`: the true values, as pandas reads them from the CSV.
* `y_pred`: classification: the most likely label, with no threshold. Regression: the predicted value.
* `y_proba`: classification: one column per class, in sorted order. Regression: `None`.
* `y_train`: the training target. Use it for the class order or a scale.

Put a threshold on `y_proba`, never on `y_pred`. Name a class by its label, not its position. Use only numpy, pandas and scikit-learn, and read no files.

## A fitted step

For a decision the model does not make by itself, add `fit` and `transform`. `fit` learns a few numbers from the out-of-fold predictions. `transform` applies them before `score`. See [Post-processing](https://docs.priorlabs.ai/autofit/how-it-works/post-processing.md).

For a threshold on two classes, you do not need your own step. Ask for the built-in threshold step, and it tunes the cut for your metric.

## Checks and limits

Autofit refuses to start unless the file scores perfect predictions better than a constant guess. This usually catches a flipped `GREATER_IS_BETTER`.

A file with a fitted step must fit, transform and score the table in under 0.1 seconds. The ensemble search calls it once for every blend it tries, often more than a thousand times after each experiment.

> [!NOTE]
>
> The session keeps a locked copy of the file. Editing the file later changes nothing in the session. A changed metric needs a new session, and only sessions with the same file content can be compared.


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