Cross validation
Skill Amey-Thakur/AI-SKILLS/skills/machine-learning/cross-validation
Plug-and-play skills and prompts for every AI coding agent
npx -y skills add Amey-Thakur/AI-SKILLS --skill cross-validationAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 21 days oldThe repository was created 21 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Pick CV schemes that respect time and grouping, nest them for tuning, and read the variance, not just the mean. Use when data is too small for a single split or when validating tuning claims.
SKILL.md
3.0 KB, 639 tokens by cl100k_base, as published. Nobody here has run it
Cross-validation
CV answers "how much does my estimate depend on which rows landed where" by averaging over K splits. It only works when every fold respects the same boundaries deployment will face; a leaky fold structure launders leakage into confidence.
Method
- Choose the scheme from the data's dependence structure. IID rows: stratified K-fold (K=5-10; stratify on the label, especially when imbalanced; see imbalanced-data). Repeated measures per entity: GroupKFold on the entity so no user/patient/device spans folds (see train-test-discipline). Temporal data: walk-forward (expanding or sliding window, train always before test); shuffled K-fold on time series is the canonical way to publish a model that cannot predict anything.
- Run the entire pipeline inside each fold. Scaling, imputation, encoding, feature selection, resampling: all fit on the fold's training portion only (pipeline objects make this automatic; see feature-engineering). Preprocessing fit on the full dataset before CV is the most common silent inflation in applied work.
- Nest when CV both tunes and evaluates. Inner loop selects hyperparameters (see hyperparameter-tuning), outer loop estimates generalization of the whole selection procedure; the outer score is the honest one. Tuning and reporting on the same folds overstates performance by exactly the amount the search exploited them.
- Report the spread with the mean. Per-fold scores, mean, and standard deviation; overlapping spreads between model A and B is a tie (see model-evaluation on uncertainty). One anomalous fold is information: inspect it (a segment? a time period?), do not average it away (see ml-error-analysis).
- Keep a final untouched test set anyway. CV replaces the validation role at small scale, not the test role: model and protocol decisions accumulate against the CV estimate, so the last word comes from data no fold ever saw (see train-test-discipline).
- Match the final refit to the protocol. Standard practice: select config by CV, refit on all training data with that config, confirm on test. For iterative learners early-stopped per fold, set the final iteration count from the folds' median rather than re-early-stopping on test.
Boundaries
- At large data scale, a single well-constructed temporal/group split estimates as well as CV at a tenth the compute; CV's value concentrates where data is scarce.
- CV variance understates true uncertainty when folds share an entity, a time regime, or collection artifacts; the scheme can only respect boundaries you know to encode.
- Leave-one-out is high-variance and expensive for most learners; prefer K=5-10 unless a statistical reason says otherwise.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.