What you will be able to do
- Explain why one train-validation split gives a validation score that depends on which rows ended up in the validation set
- Describe how k-fold cross-validation uses every row for both training and evaluation, and why that matters on small datasets
- Estimate the extra compute cross-validation costs and say when a single split is the better choice
- Recognise what cross-validation does not do: it does not replace the test set, create new rows, or suit time-ordered data when folds are random
Key concept
k-fold cross-validation — The training data is cut into k folds. Each fold is held out once while a model trains on the other k−1 folds, and the reported metric is the average of the k held-out scores. You get a steadier, more data-efficient estimate than one split gives, and you pay for it with k fits per candidate model.
1.Why a single train-validation split gives a noisy score
A train-validation split holds back part of the data, fits the model on the rest and scores it on the rows held back. The resulting number is meant to predict how the model will do on data it has never seen. Databricks AutoML uses this design by default: when you do not choose a split strategy, the dataset is randomly divided into train, validate and test portions.
The weakness is that you get one number from one random partition. Suppose a churn dataset has 800 labelled rows and you split it 80/20. The validation set has 160 rows, so each misclassified row moves accuracy by about 0.6 percentage points. If one seed happens to put several hard-to-predict customers in validation and another seed doesn't, accuracy can swing from 0.71 to 0.83 with no change to the model. The model hasn't changed between those runs, only the luck of the draw, and the split cannot tell you which number is closer to the truth.
Two other fixes look reasonable and also fail. Growing the validation share from 20% to 40% steadies the validation score a little, but it takes those rows away from training, which is the opposite of what a small dataset needs. Rerunning several times and reporting the best score is worse: it is selection bias, and it pushes the reported number toward the lucky end of the range. To actually reduce the noise, the estimate has to come from more than one partition.
A single split also leaves data unused for training. Data that sits in a validation set never trains the model. When the data is also split into a test set, the training share gets smaller again, which hurts most when there were few rows to start with.
Checkpoint 1 of 8· Check yourself
Validation accuracy for an 800-row churn model, scored on an 80/20 split, swings between 0.71 and 0.83 depending on the split. Which change actually reduces the noise in the estimate without costing the model training data?
The noise comes from scoring on a single random partition, so the estimate has to come from more than one partition and be averaged. Reporting the best rerun is selection bias toward the lucky end of the range. A larger validation share or an extra test set both take rows away from training, and the score is still tied to one particular split.
“the results can depend on a particular random choice for the pair of (train, validation) sets.”Source: scikit-learn.org
2.How k-fold cross-validation averages away the noise
k-fold cross-validation repeats the split k times in a structured way. The training data is cut into k folds of roughly equal size. In each round, one fold is held out for scoring and a fresh model is trained on the other k−1 folds. After k rounds, every row has been scored exactly once and has been used for training k−1 times. The reported metric is the mean of the k fold scores, and their spread shows how much the estimate moves from partition to partition.
>>> from sklearn.model_selection import cross_val_score
>>> clf = svm.SVC(kernel='linear', C=1, random_state=42)
>>> scores = cross_val_score(clf, X, y, cv=5)
>>> scores
array([0.96, 1. , 0.96, 0.96, 1. ])Each fold score is just as noisy as a single split. Averaging five of them gives a more trustworthy figure for the 800-row churn model than any one seed's 0.71 or 0.83. The data efficiency matters even more on a 400-row dataset. A fixed validation set would keep 80 rows out of training for good. With five-fold cross-validation, every row helps train four of the five models and is scored by the fifth. Cross-validation does not create synthetic rows or increase the sample size. It reuses the rows you already have in both roles.
The same idea is used in Databricks tuning examples. Instead of scoring each candidate hyperparameter value on one holdout, the objective function below returns the mean cross-validated accuracy, so candidates are ranked on an average and not on one lucky partition. This example uses Hyperopt, which has since been deprecated on Databricks, but the cross-validation pattern is the same whichever tuning library calls it. Running cross-validation inside a fitting or tuning workflow is covered in cross-validation as part of model fitting.
def objective(C):
# Create a support vector classifier model
clf = SVC(C=C)
# Use the cross-validation accuracy to compare the models' performance
accuracy = cross_val_score(clf, X, y).mean()
# Hyperopt tries to minimize the objective function. A higher accuracy value means a better model, so you must return the negative accuracy.
return {'loss': -accuracy, 'status': STATUS_OK}Checkpoint 2 of 8· Fill the gap
This tuning objective gives Hyperopt one number for each candidate C. Which array method should complete it so that candidates are ranked fairly across the folds?
def objective(C):
# Create a support vector classifier model
clf = SVC(C=C)
# Use the cross-validation accuracy to compare the models' performance
accuracy = cross_val_score(clf, X, y). ? ()
# Hyperopt tries to minimize the objective function. A higher accuracy value means a better model, so you must return the negative accuracy.
return {'loss': -accuracy, 'status': STATUS_OK}cross_val_score returns one score per held-out fold. Taking the mean ranks each candidate on an average across partitions. Taking the max would rank it on its luckiest fold, which is the same selection bias as reporting the best of several reruns.
Source: docs.databricks.comCheckpoint 3 of 8· Check yourself
A team with 400 labelled rows replaces its train/validate/test split with five-fold cross-validation to tune a model. What should happen to the test set?
Cross-validation replaces the validation set, not the test set. The folds were used to choose hyperparameters, and picking the best candidate on the same folds favours the one that got lucky on those rows, so the fold mean is optimistic. A test set held out before any folds are made gives the final, one-time evaluation.
“A test set should still be held out for final evaluation, but the validation set is no longer needed when doing CV.”Source: scikit-learn.org
Checkpoint 4 of 8· Exam question
A data scientist has 800 labeled rows for a churn model, and a single 80/20 train-validation split produces a validation accuracy that swings between 0.71 and 0.83 depending on the random seed used for the split. The team wants a more trustworthy estimate of how the model will generalize before presenting results to stakeholders. Which change addresses this instability?
Correct answer: A — Switch to cross_val_score with 5-fold cross-validation so the reported metric averages five different train/test partitions instead of one arbitrary split.
- A. Five-fold cross-validation trains and evaluates the model on five distinct partitions of the data and averages the resulting scores, which directly reduces the variance caused by depending on one arbitrary split and gives a more reliable generalization estimate.
- B. Enlarging the validation set shrinks the training set even further on an already small 800-row dataset, which can hurt model quality and does not address the underlying problem that only one random partition is being evaluated.
- C. Fixing the random seed makes the result reproducible but does not make it more reliable — it locks in whichever lucky or unlucky split was drawn instead of averaging across several partitions.
- D. Repeating training on the identical split and keeping only the best score does not reduce variance at all; it introduces selection bias by cherry-picking the most favorable run rather than averaging independent estimates.
Checkpoint 5 of 8· Exam question
A team is training a gradient-boosted tree model on a dataset with only 400 rows, which is too small to comfortably carve out a separate validation set without starving the training set. Which property of k-fold cross-validation makes it a better fit than a single train-validation split for this specific situation?
Correct answer: A — Every row is used for training in some folds and for testing in exactly one fold, so the full dataset contributes to both training and evaluation instead of being permanently set aside as a validation set.
- A. This is correct: with k folds, each row serves as training data in k-1 folds and as test data in exactly one fold, so no data is permanently sacrificed to a validation set the way it would be with a single split, which matters most when the total row count is already small.
- B. Cross-validation does not generate synthetic rows or otherwise increase the dataset size; it only reorganizes how the existing 400 rows are partitioned across repeated train/test cycles.
- C. Cross-validation is typically used during model selection and hyperparameter tuning, but a separate held-out test set is still recommended for a final, unbiased evaluation of the chosen model; it does not eliminate that need.
- D. Cross-validation requires more model fits, not fewer, since a model is trained once per fold instead of once for a single split, so it increases rather than reduces total training cost for expensive models like gradient-boosted trees.
3.The cost: k fits for every candidate
Every fold trains a separate model, so cross-validation multiplies training work by about k. One train-validation split fits each candidate once. Ten-fold cross-validation fits it ten times. In a hyperparameter search the multiplier applies to every candidate, so a search that fits 20 candidates on one split fits 200 models with ten folds. Spark ML has the same pair of choices: TrainValidationSplit scores each candidate on one holdout and CrossValidator scores it across folds. How to count every model in a grid search with cross-validation, including the final refit, is covered in counting models in grid search and cross-validation.
About ten fits of roughly 45 million rows each (nine of the ten folds), so around 27 hours of training compute for that one setting. A single split needs one fit.
Parallel execution reduces wall-clock time, not total compute. Fold fits are independent of each other, so they can run at the same time. Spark's CrossValidator has a parallelism setting for this, and Databricks tuning tools have a similar setting for running trials concurrently. Thirty hours of fitting is still thirty hours of cluster time, even if it finishes sooner. Running folds in parallel is covered in parallelizing single-node models for tuning.
At large scale, the multiplier usually doesn't pay for itself. Cross-validation is not less accurate on 50 million rows. It is less necessary. A 20% holdout of 50 million rows has 10 million validation rows, so its score barely moves from seed to seed, and giving up those rows from training costs almost nothing. The benefits of cross-validation, a lower-variance estimate and full use of scarce data, are largest on small datasets and become negligible on large ones, while the cost keeps growing.
Cross-validation also involves more setup. Any preprocessing that learns from data, such as scaling, imputation or encoding, has to be refit inside each fold on that fold's training rows. Otherwise statistics from the held-out fold leak into training and inflate every fold score. Putting the preprocessing and the model in one pipeline handles this. See building a training pipeline.
Checkpoint 6 of 8· Check yourself
A team tunes 15 gradient-boosted candidates on 30 million rows, and one fit takes about two hours. Why is a single 80/20 train-validation split the better choice than five-fold cross-validation here?
Cross-validation multiplies training work by about k for every candidate, and its benefit (a lower-variance estimate) is negligible when the holdout already has millions of rows. Fold fits can run in parallel and the estimate is no worse. On large data cross-validation is less necessary, not less accurate.
“This approach can be computationally expensive, but does not waste too much data (as is the case when fixing an arbitrary validation set)”Source: scikit-learn.org
Checkpoint 7 of 8· Exam question
A data scientist is deciding between a single train-validation split and 10-fold cross-validation for tuning a random forest on a dataset with 50 million rows, where a single training run already takes several hours on the cluster. Which downside of cross-validation is most relevant to this decision?
Correct answer: A — Cross-validation multiplies total training time by roughly the number of folds, since a separate model must be fit for each fold instead of the single fit required by a train-validation split.
- A. With k-fold cross-validation, a full model fit happens for every fold, so ten folds mean roughly ten times the compute of a single train-validation split; on an already multi-hour training job at 50 million rows, that multiplier is the dominant cost concern.
- B. Fold-level training runs are independent of each other and can be distributed across a cluster (for example with
SparkTrialsor parallel job execution), so lack of parallelism is not an inherent limitation of cross-validation. - C. Cross-validation does not produce a less accurate estimate on large datasets; if anything, its averaged estimate is at least as reliable as a single split, so accuracy loss is not the tradeoff at play here.
- D. Cross-validation does not require the full dataset to be held in driver memory any more than a single split does — both approaches operate on the same distributed dataset, so memory footprint is not the distinguishing downside.
4.Choosing between cross-validation and a single split
Choose based on two things: how much data you have and how expensive one fit is. When rows are scarce and each fit is quick, cross-validation gives a much more reliable estimate for little extra cost. When data is plentiful and each fit takes hours, a single split gives an estimate that is already stable, at a fraction of the cost.
| Aspect | Single split (train_test_split, TrainValidationSplit) | k-fold (cross_val_score, CrossValidator) |
|---|---|---|
| Fits per candidate | 1 | k |
| How the estimate is formed | One score from one random partition | Mean (and spread) of k held-out fold scores |
| Rows used for training | Only the training share; validation rows never train | Every row trains in k−1 folds and is scored in one |
| Sensitivity to the split seed | High on small data | Much lower; noise averages out across folds |
| Best fit | Large datasets, expensive models, quick iteration | Small or moderate datasets, final model comparisons |
| Separate test set still needed | Yes | Yes |
Checkpoint 8 of 8· Match them up
Match each evaluation approach to the project it suits best, given how much data there is, how long one fit takes and how the rows are ordered.
Tap a term, then the definition that fits it.
Cross-validation costs about k fits, and in return it gives a steadier estimate and uses every row for training. That trade pays off when rows are scarce and fits are cheap. With millions of rows, a single holdout is already stable at a fraction of the cost. Random folds would let a model train on rows from after the period it is scored on, so time-ordered data needs folds that move forward in time.
“This approach can be computationally expensive, but does not waste too much data”Source: scikit-learn.org
Sources5
Sources
(5)
Every claim above is drawn from one of these pages, quoted as it was written on the date shown.
- 1.
“the dataset is randomly split into 60% train split, 20% validate split, and 20% test split.”
↩︎ Why a single train-validation split gives a noisy score - 2.https://scikit-learn.org/stable/modules/cross_validation.htmlSecondary source
“by partitioning the available data into three sets, we drastically reduce the number of samples which can be used for learning the model”
↩︎ Why a single train-validation split gives a noisy score“A test set should still be held out for final evaluation, but the validation set is no longer needed when doing CV.”
↩︎ How k-fold cross-validation averages away the noise“because the parameters can be tweaked until the estimator performs optimally.”
↩︎ How k-fold cross-validation averages away the noise“This approach can be computationally expensive, but does not waste too much data (as is the case when fixing an arbitrary validation set)”
↩︎ The cost: k fits for every candidate“The performance measure reported by k-fold cross-validation is then the average of the values computed in the loop.”
↩︎ Key concept“the results can depend on a particular random choice for the pair of (train, validation) sets.”
↩︎ Exam trap 1“A test set should still be held out for final evaluation, but the validation set is no longer needed when doing CV.”
↩︎ Exam trap 2“This approach can be computationally expensive, but does not waste too much data (as is the case when fixing an arbitrary validation set)”
↩︎ Exam trap 3“the results can depend on a particular random choice for the pair of (train, validation) sets.”
↩︎ Prediction“This approach can be computationally expensive, but does not waste too much data”
↩︎ Checkpoint - 3.https://docs.databricks.com/aws/en/machine-learning/automl-hyperparam-tuning/hyperopt-spark-mlflow-integrationOfficial docs
“Use the cross-validation accuracy to compare the models' performance”
↩︎ How k-fold cross-validation averages away the noise“parallelism: Number of models to fit and evaluate concurrently.”
↩︎ The cost: k fits for every candidate - 4.https://docs.databricks.com/aws/en/machine-learning/ai-runtime/examples/tutorials/sgc-xgboost-optuna-tuningOfficial docs
“Hold out a test set used only for the final evaluation”
↩︎ How k-fold cross-validation averages away the noise - 5.
“For forecasting tasks, AutoML uses time series cross-validation.”
↩︎ Choosing between cross-validation and a single split“This method incrementally extends the training dataset chronologically and performs validation on subsequent time points.”
↩︎ Choosing between cross-validation and a single split