K-fold cross-validation estimates model performance without requiring a separate validation split. H2O-3 integrates cross-validation directly into the training process via theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/h2oai/h2o-3/llms.txt
Use this file to discover all available pages before exploring further.
nfolds parameter.
How cross-validation works in H2O-3
When you setnfolds=5, H2O-3 builds 6 models:
- 5 cross-validation models, each trained on 80% of the data with a different 20% held out.
- 1 main model, trained on 100% of the training data.
Combining holdout predictions this way can yield slightly different results than averaging the 5 individual validation metrics, especially when fold sizes differ or when models converge to different local minima (e.g., small Deep Learning models).
Basic example
Custom fold assignment with fold_column
For structured data — such as time-series, geographic, or grouped data — random fold splitting can cause data leakage. Usefold_column to specify an explicit per-row fold assignment.
Keeping cross-validation predictions
By default, holdout predictions and fold assignments are deleted from memory after training completes. Setkeep_cross_validation_predictions=True to retain the per-fold prediction frames.
Keeping fold assignments
To retain the fold assignment column used during cross-validation, setkeep_cross_validation_fold_assignment=True.
Accessing cross-validation metrics
Train with nfolds
Set
nfolds greater than 1 when calling train(). H2O-3 will automatically build the K cross-validation models along with the main model.Retrieve cross-validation performance
Access the cross-validated metrics from the main model object using
xval=True (Python) or xval = TRUE (R).Cross-validation cleanup
By default, when the main model finishes training, H2O-3 automatically removes these objects from memory:- Cross-validation models
- Cross-validation metrics
- Holdout predictions
- Fold assignments
| Flag | Purpose |
|---|---|
keep_cross_validation_models | Retain the K fold models |
keep_cross_validation_predictions | Retain per-fold and combined holdout prediction frames |
keep_cross_validation_fold_assignment | Retain the fold assignment column |
If training is interrupted by a timeout or manual cancellation, H2O-3 also attempts to remove the associated CV models and residuals from memory.