loss

Regression error for support vector machine regression model

Syntax

L = loss(mdl,tbl,ResponseVarName)
L = loss(mdl,tbl,Y)
L = loss(mdl,X,Y)
L = loss(___,Name,Value)

Description

L = loss(mdl,tbl,ResponseVarName) returns the loss for the predictions of the support vector machine (SVM) regression model, mdl, based on the predictor data in the table tbl and the true response values in tbl.ResponseVarName.

L = loss(mdl,tbl,Y) returns the loss for the predictions of the support vector machine (SVM) regression model, mdl, based on the predictor data in the table X and the true response values in the vector Y.

L = loss(mdl,X,Y) returns the loss for the predictions of the support vector machine (SVM) regression model, mdl, based on the predictor data in X and the true responses in Y.

L = loss(___,Name,Value) returns the loss with additional options specified by one or more Name,Value pair arguments, using any of the previous syntaxes. For example, you can specify the loss function or observation weights.

Input Arguments

expand all

SVM regression model, specified as a RegressionSVM model or CompactRegressionSVM model returned by fitrsvm or compact, respectively.

Sample data, specified as a table. Each row of tbl corresponds to one observation, and each column corresponds to one predictor variable. Optionally, tbl can contain additional columns for the response variable and observation weights. tbl must contain all of the predictors used to train mdl. Multi-column variables and cell arrays other than cell arrays of character vectors are not allowed.

If you trained mdl using sample data contained in a table, then the input data for this method must also be in a table.

Data Types: table

Response variable name, specified as the name of a variable in tbl. The response variable must be a numeric vector.

You must specify ResponseVarName as a character vector or string scalar. For example, if the response variable Y is stored as tbl.Y, then specify ResponseVarName as 'Y'. Otherwise, the software treats all columns of tbl, including Y, as predictors when training the model.

Data Types: char | string

Predictor data, specified as a numeric matrix or table. Each row of X corresponds to one observation (also known as an instance or example), and each column corresponds to one variable (also known as a feature).

If you trained mdl using a matrix of predictor values, then X must be a numeric matrix with p columns. p is the number of predictors used to train mdl.

The length of Y and the number of rows of X must be equal.

Data Types: single | double

Observed response values, specified as a vector of length n containing numeric values. Each entry in Y is the observed response based on the predictor data in the corresponding row of X.

Data Types: single | double

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 quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Loss function, specified as the comma-separated pair consisting of 'LossFun' and 'mse', 'epsiloninsensitive', or a function handle.

  • The following table lists the available loss functions.

    ValueLoss Function
    'mse'Weighted Mean Squared Error
    'epsiloninsensitive'Epsilon-Insensitive Loss Function
  • Specify your own function using function handle notation.

    Your function must have the signature lossvalue = lossfun(Y,Yfit,W), where:

    • The output argument lossvalue is a scalar value.

    • You choose the function name (lossfun).

    • Y is an n-by-1 numeric vector of observed response values.

    • Yfit is an n-by-1 numeric vector of predicted response values, calculated using the corresponding predictor values in X (similar to the output of predict).

    • W is an n-by-1 numeric vector of observation weights. If you pass W, the software normalizes them to sum to 1.

    Specify your function using 'LossFun',@lossfun.

Example: 'LossFun','epsiloninsensitive'

Data Types: char | string | function_handle

Observation weights, specified as the comma-separated pair consisting of 'Weights' and a numeric vector. Weights must be the same length as the number of rows in X. The software weighs the observations in each row of X using the corresponding weight value in Weights.

Weights are normalized to sum to 1.

Data Types: single | double

Output Arguments

expand all

Regression loss, returned as a scalar value.

Examples

expand all

This example shows how to train an SVM regression model, then calculate the resubstitution mean square error and epsilon-insensitive error.

Load the carsmall sample data.

load carsmall
rng default  % for reproducibility

Specify Horsepower and Weight as the predictor variables (X), and MPG as the response variable (Y).

X = [Horsepower,Weight];
Y = MPG;

Train a linear SVM regression model. Standardize the data.

mdl = fitrsvm(X,Y,'Standardize',true);

mdl is a RegressionSVM model.

Determine how well the trained model generalizes to new predictor values by estimating the test sample mean square error and epsilon-insensitive error.

lossMSE = loss(mdl,X,Y)
lossEI = loss(mdl,X,Y,'LossFun','epsiloninsensitive')
lossMSE =

   17.0256


lossEI =

    2.2506

More About

expand all

Tips

Extended Capabilities

Introduced in R2015b