Skip to main content
When no built-in metric 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:

The file

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