This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: RegressionPartitionedEnsemble

Cross-validation loss of partitioned regression ensemble


L = kfoldLoss(cvens)
L = kfoldLoss(cvens,Name,Value)


L = kfoldLoss(cvens) returns the cross-validation loss of cvens.

L = kfoldLoss(cvens,Name,Value) returns cross-validation loss 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


Object of class RegressionPartitionedEnsemble. Create obj with fitrensemble along with one of the cross-validation options: 'crossval', 'kfold', 'holdout', 'leaveout', or 'cvpartition'. Alternatively, create obj from a regression ensemble with crossval.

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.


Indices of folds ranging from 1 to cvens.KFold. Use only these folds for predictions.

Default: 1:cvens.KFold


Function handle for loss function, or 'mse', meaning mean squared error. If you pass a function handle fun, loss calls it as


where Y, Yfit, and W are numeric vectors of the same length.

  • Y is the observed response.

  • Yfit is the predicted response.

  • W is the observation weights.

The returned value fun(Y,Yfit,W) should be a scalar.

Default: 'mse'


Character vector representing the meaning of the output L:

  • 'ensemble'L is a scalar value, the loss for the entire ensemble.

  • 'individual'L is a vector with one element per trained learner.

  • 'cumulative'L is a vector in which element J is obtained by using learners 1:J from the input list of learners.

Default: 'ensemble'

Output Arguments


The loss (mean squared error) between the observations in a fold when compared against predictions made with an ensemble trained on the out-of-fold data. L can be a vector, and can mean different things, depending on the name-value pair settings.


expand all

Find the cross-validation loss for a regression ensemble of the carsmall data.

Load the carsmall data set and select displacement, horsepower, and vehicle weight as predictors.

load carsmall
X = [Displacement Horsepower Weight];

Train an ensemble of regression trees.

rens = fitrensemble(X,MPG);

Create a cross-validated ensemble from rens and find the k-fold cross-validation loss.

rng(10,'twister') % For reproducibility
cvrens = crossval(rens);
L = kfoldLoss(cvrens)
L = 28.8593
Was this topic helpful?