Skip to content

ML.EVAL.CV_SCORE

Cross-validates the model and returns the per-fold score array (length=cv).

Syntax

ML.EVAL.CV_SCORE(model, X, y, cv, scoring)

Arguments

Name Type Default Description
model object Estimator or pipeline object (e.g. created by ML.CLASSIFICATION., ML.REGRESSION., ML.CLUSTERING.*, or ML.PIPELINE).
X object DataFrame object of features.
y object DataFrame or array object of target values.
cv int Number of cross-validation folds. Each fold trains on (cv-1)/cv of the data and scores on the remaining 1/cv.
scoring str Name of the scoring metric to use (e.g. 'accuracy', 'r2', 'neg_mean_squared_error'). See scikit-learn's scoring strings.

Returns

A 1-D array of length cv — one fold-level score per cross-validation fold. Higher is better when scoring is an accuracy / R² metric; lower is better when it's a loss.

When to use

Reach for cv_score when a single train/test split isn't enough to trust a model's score. Cross-validation re-runs the fit-and-score loop cv times on different folds of the data and gives you the per-fold scores back as an array, so you can see how stable the score is.

The function returns the per-fold scores, not a single mean. The array spills across cv cells in your sheet — average them with Excel's AVERAGE, chart them, or compare two models fold-by-fold.

This is the right tool when:

  • You suspect a single train/test split was lucky or unlucky.
  • You want to compare two pipelines (e.g. SVM vs StandardScaler + SVM) on the same folds and see the spread, not just the mean.
  • The dataset is small and a 20% holdout would leave too few rows for a reliable score.

Examples

5-fold cross-validate a bare SVM on raw features:

=ML.CLASSIFICATION.SVM(1, "rbf", , "scale")
=ML.EVAL.CV_SCORE(F1, A2:M179, N2:N179, 5, "accuracy")

The result spills into 5 cells. Average them inline:

=AVERAGE(F2#)

Cross-validate a pipeline that scales first, then fits SVM — fold-by-fold the gap to the bare SVM is the visual punchline of "scaling matters":

=ML.PREPROCESSING.STANDARD_SCALER()
=ML.CLASSIFICATION.SVM(1, "rbf", , "scale")
=ML.PIPELINE(F1, F2)
=ML.EVAL.CV_SCORE(F3, A2:M179, N2:N179, 5, "accuracy")

Remarks

  • The fold splitter is scikit-learn's default — KFold for regression targets and StratifiedKFold for classification targets, both with shuffle=False. The same cv value therefore produces identical splits across runs without needing a random seed.
  • Pass a single, untrained estimator. If you pass a fitted model the fit state is ignored — cv_score re-fits on each training fold from scratch.
  • Pre-process inside a ML.PIPELINE, not outside — if you scale X before calling cv_score, every fold has been fit on data that "saw" the test fold's mean and standard deviation, and the score is silently optimistic.
  • scoring accepts any string sklearn understands — e.g. "accuracy", "f1_weighted", "r2", "neg_mean_squared_error", "roc_auc_ovr".
  • Premium feature: requires a paid formulaML role.

See also