Class: RegressionEnsemble

Cross validate ensemble


cvens = crossval(ens)
cvens = crossval(ens,Name,Value)


cvens = crossval(ens) creates a cross-validated ensemble from ens, a regression ensemble. Default is 10-fold cross validation.

cvens = crossval(ens,Name,Value) creates a cross-validated ensemble with additional options specified by one or more Name,Value pair arguments. You can specify several name-value pair arguments in any order as Name1,Value1,…,NameN,ValueN.

Input Arguments


A regression ensemble created with fitensemble.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


A partition of class cvpartition. Sets the partition for cross validation.

Use no more than one of the name-value pairs cvpartition, holdout, kfold, and leaveout.


Holdout validation tests the specified fraction of the data, and uses the rest of the data for training. Specify a numeric scalar from 0 to 1. You can only use one of these four options at a time for creating a cross-validated tree: 'kfold', 'holdout', 'leaveout', or 'cvpartition'.


Number of folds for cross validation, a numeric positive scalar.

Use no more than one of the name-value pairs 'kfold', 'holdout', 'leaveout', or 'cvpartition'.


If 'on', use leave-one-out cross-validation.

Use no more than one of the name-value pairs 'kfold', 'holdout', 'leaveout', or 'cvpartition'.


Printout frequency, a positive integer scalar. Use this parameter to observe the training of cross-validation folds.

Default: 'off', meaning no printout

Output Arguments


A cross-validated classification ensemble of class RegressionPartitionedEnsemble.


You can create a cross-validation ensemble directly from the data, instead of creating an ensemble followed by a cross-validation ensemble. To do so, include one of these five options in fitensemble: 'crossval', 'kfold', 'holdout', 'leaveout', or 'cvpartition'.


Create a cross-validated classification model for the carsmall data, and assess its quality using the kfoldLoss method:

X = [Acceleration Displacement Horsepower Weight];
rens = fitensemble(X,MPG,'LSBoost',100,'Tree');
cvens = crossval(rens);
L = kfoldLoss(cvens)

L =
Was this topic helpful?