Regression · Selection

Cross-Validated Model Comparison

Compare candidate model families (OLS/Ridge/Lasso/KNN for regression, Logistic/Ridge/KNN for classification) by k-fold or leave-one-out cross-validation, with a one-standard-error-rule pick.

In the menus Regression › Selection › Cross-Validated Model Comparison

Also searched as cross validation k fold kfold compare models model comparison train test split

When to use it

You have one outcome and a predictor set and want to choose a model by honest out-of-sample error instead of in-sample fit: the ISLR cross-validation workflow. Compares several model families head-to-head and applies the one-standard-error rule.

When not to: The rows are time-ordered (use the forecast backtest instead, since ordinary CV assumes exchangeable rows), the data are clustered or grouped in a way plain k-fold would leak across, or you already know which single model you want to fit and just need to interpret its coefficients (use linear or logistic regression directly).

Step by step

  1. Open it from the menu

    Click Regression in the menu bar; under Selection choose Cross-Validated Model Comparison.

  2. Fill in the form

    Choose the columns: What you want to predict or explain, Columns that may explain it. The form lists only columns whose type fits each field.

  3. Check the options

    The options start at their defaults: Task type, CV method, Folds (k), KNN neighbors, Ridge α, Lasso α. Change one only when your question needs it.

  4. Run the analysis

    Press Run analysis. The Result Card opens on its Results tab.

What to choose in the form

Fields of the Cross-Validated Model Comparison form
What you want to predict or explain Response requiredOne numeric or binary or categorical or ordered categorical column. Outcome to predict. Continuous → regression (CV RMSE); categorical / two-valued → classification (CV accuracy).
Columns that may explain it Predictors requiredOne numeric column. One or more numeric predictor columns (X).
Task typeForce regression / classification, or auto-detect from the outcome. Default: auto.
CV methodk-fold cross-validation or leave-one-out (LOOCV). Default: kfold.
Folds (k)Number of folds for k-fold CV (ignored for LOOCV). Auto-reduced if n is small. Default: 5.
KNN neighborsNumber of neighbors for the KNN candidate. Default: 5.
Ridge αL2 penalty strength for the Ridge candidate. Default: 1.
Lasso αL1 penalty strength for the Lasso candidate (regression only). Default: 1.

How to read the card

The Results tab starts with what to know first (rows left out, checks that did not pass), then the interpretation in words and the Key Results; charts and assumption checks follow further down. Learn More explains the method in plain words. Read a Result Card covers all four tabs.

What it assumes

Independence of observations

If it does not hold: A random k-fold split lets information leak across time or across a cluster/group boundary (e.g. repeated measurements on the same subject landing in both the training and test fold), so the reported CV error is optimistically biased and does not reflect true out-of-sample performance for that structure.

How to check: Not checked by KernelStats: the engine always applies a seeded random (or exhaustive, for LOOCV) row split and does not detect time ordering or grouping structure among the predictors; a time-indexed or clustered dataset needs to be recognized by the analyst, who should use Forecast Backtest (Rolling-Origin) for a time series instead.

A worked example

Predicting penguin body mass from bill length and flipper length, comparing Lasso, Ridge, OLS, and KNN (k=5) by 5-fold CV RMSE with a seeded split.

Result: Mean CV RMSE ± SE across folds: Lasso 392.6 ± 16.2 g, Ridge 392.6 ± 16.3 g, OLS 392.6 ± 16.2 g, KNN 384.2 ± 8.3 g. KNN is best, so the one-SE band is RMSE <= 384.2 + 8.3 = 392.5 g; the three linear models miss it by about 0.1 g, so the band holds only KNN and the rule picks KNN.

The rule is mechanical: it uses only the best model's standard error, so a 0.1 g miss sends the pick to KNN even though an 8 g difference on errors of about 390 g, with fold-to-fold standard errors of 8-16 g, is practically nothing. The honest reading is that all four candidates predict about equally well; the analyst can reasonably prefer the interpretable linear model, saying so explicitly rather than presenting the automatic pick as a verdict.

From the Statistics Library.

The code tabs

Code gives this analysis as Python, R and MATLAB code (and SAS where the tab offers it), reading the data the way KernelStats did. Export sends the card to a report or to slides. See The Code tab.

Understand the statistics

Ask Oobi

Type one of these into Ask Oobi beside your data:

  • For predicting penguin body mass, does a flexible KNN beat linear models once I judge them by cross-validated error?
  • Explain the cross-validated model comparison in plain words.
  • What does cross-validation mean?

Last reviewed November 16, 2026.

Report an unclear step