Documentation Center |
L = loss(ens,X,Y)
L = loss(ens,X,Y,Name,Value)
L = loss(ens,X,Y) returns the mean squared error between the predictions of ens to the data in X, compared to the true responses Y.
L = loss(ens,X,Y,Name,Value) computes the error in prediction with additional options specified by one or more Name,Value pair arguments.
ens |
A regression ensemble created with fitensemble, or the compact method. |
X |
A matrix of predictor values. Each column of X represents one variable, and each row represents one observation. NaN values in X are taken to be missing values. Observations with all missing values for X are not used in the calculation of loss. |
Y |
A numeric column vector with the same number of rows as X. Each entry in Y is the response to the data in the corresponding row of X. NaN values in Y are taken to be missing values. Observations with missing values for Y are not used in the calculation of loss. |
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.
'learners' |
Indices of weak learners in the ensemble ranging from 1 to ens.NumTrained. oobEdge uses only these learners for calculating loss. Default: 1:NumTrained |
'lossfun' |
Function handle for loss function, or the string 'mse', meaning mean squared error. If you pass a function handle fun, loss calls it as fun(Y,Yfit,W) where Y, Yfit, and W are numeric vectors of the same length.
The returned value fun(Y,Yfit,W) should be a scalar. Default: 'mse' |
'mode' |
String representing the meaning of the output L:
Default: 'ensemble' |
'UseObsForLearner' |
A logical matrix of size N-by-NumTrained, where N is the number of observations in ens.X, and NumTrained is the number of weak learners. When UseObsForLearner(I,J) is true, predict uses learner J in predicting observation I. Default: true(N,NumTrained) |
'weights' |
Numeric vector of observation weights with the same number of elements as Y. The formula for loss with weights is in Weighted Mean Squared Error. Default: ones(size(Y)) |
L |
Weighted mean squared error of predictions. The formula for loss is in Weighted Mean Squared Error. |
Let n be the number of rows of data, x_{j} be the jth row of data, y_{j} be the true response to x_{j}, and let f(x_{j}) be the response prediction of ens to x_{j}. Let w be the vector of weights (all one by default).
First the weights are divided by their sum so they add to one: w→w/Σw. The mean squared error L is
Find the loss of an ensemble predictor of the carsmall data to find MPG as a function of engine displacement, horsepower, and vehicle weight:
load carsmall X = [Displacement Horsepower Weight]; ens = fitensemble(X,MPG,'LSBoost',100,'Tree'); L = loss(ens,X,MPG) L = 4.3904