CompactRegressionSVM.predict - Predict responses using support vector machine regression model - MATLAB (original) (raw)

Class: classreg.learning.regr.CompactRegressionSVM, RegressionSVM
Namespace: classreg.learning.regr

Predict responses using support vector machine regression model

Syntax

Description

[yfit](#buvlclx-yfit) = predict([Mdl](#buvlclx-Mdl),[X](#buvlclx-X)) returns a vector of predicted responses for the predictor data in the table or matrix X, based on the full or compact, trained support vector machine (SVM) regression model Mdl.

example

[yfit](#buvlclx-yfit) = predict([Mdl](#buvlclx-Mdl),[X](#buvlclx-X),PredictionForMissingValue=[prediction](#buvlclx%5Fsep%5Fmw%5F0a5f3ed1-774b-425e-a442-92f5a43fb279)) uses the prediction value as the predicted response for observations with missing values in the predictor data X. By default, predict uses the median of the observed response values in the training data. (since R2023b)

Input Arguments

expand all

Predictor data used to generate responses, specified as a numeric matrix or table.

Each row of X corresponds to one observation, and each column corresponds to one variable.

If you set 'Standardize',true infitrsvm to train Mdl, then the software standardizes the columns of X using the corresponding means in Mdl.Mu and standard deviations inMdl.Sigma.

Data Types: table | double | single

Since R2023b

Predicted response value to use for observations with missing predictor values, specified as "median", "mean", or a numeric scalar.

Value Description
"median" predict uses the median of the observed response values in the training data as the predicted response value for observations with missing predictor values.
"mean" predict uses the mean of the observed response values in the training data as the predicted response value for observations with missing predictor values.
Numeric scalar predict uses this value as the predicted response value for observations with missing predictor values.

Example: "mean"

Example: NaN

Data Types: single | double | char | string

Output Arguments

Examples

expand all

Load the carsmall data set. Consider a model that predicts a car's fuel efficiency given its horsepower and weight. Determine the sample size.

load carsmall tbl = table(Horsepower,Weight,MPG); N = size(tbl,1);

Partition the data into training and test sets. Hold out 10% of the data for testing.

rng(10); % For reproducibility cvp = cvpartition(N,'Holdout',0.1); idxTrn = training(cvp); % Training set indices idxTest = test(cvp); % Test set indices

Train a linear SVM regression model. Standardize the data.

Mdl = fitrsvm(tbl(idxTrn,:),'MPG','Standardize',true);

Mdl is a RegressionSVM model.

Predict responses for the test set.

YFit = predict(Mdl,tbl(idxTest,:));

Create a table containing the observed response values and the predicted response values side by side.

table(tbl.MPG(idxTest),YFit,'VariableNames',... {'ObservedValue','PredictedValue'})

ans=10×2 table ObservedValue PredictedValue _____________ ______________

      14             9.4833    
      27             28.938    
      10              7.765    
      28             27.155    
      22             21.054    
      29             31.484    
    24.5             30.306    
    18.5              19.12    
      32             28.225    
      28             26.632    

Tips

Alternative Functionality

To integrate the prediction of an SVM regression model into Simulink®, you can use the RegressionSVM Predict block in the Statistics and Machine Learning Toolbox™ library or a MATLAB® Function block with the predict function. For examples, see Predict Responses Using RegressionSVM Predict Block and Predict Class Labels Using MATLAB Function Block.

When deciding which approach to use, consider the following:

Extended Capabilities

expand all

Thepredict function fully supports tall arrays. For more information, see Tall Arrays.

Usage notes and limitations:

For more information, see Introduction to Code Generation.

Version History

Introduced in R2015b

expand all

Starting in R2023b, when you predict or compute the loss, some regression models allow you to specify the predicted response value for observations with missing predictor values. Specify the PredictionForMissingValue name-value argument to use a numeric scalar, the training set median, or the training set mean as the predicted value. When computing the loss, you can also specify to omit observations with missing predictor values.

This table lists the object functions that support thePredictionForMissingValue name-value argument. By default, the functions use the training set median as the predicted response value for observations with missing predictor values.

Model Type Model Objects Object Functions
Gaussian process regression (GPR) model RegressionGP, CompactRegressionGP loss, predict, resubLoss, resubPredict
RegressionPartitionedGP kfoldLoss, kfoldPredict
Gaussian kernel regression model RegressionKernel loss, predict
RegressionPartitionedKernel kfoldLoss, kfoldPredict
Linear regression model RegressionLinear loss, predict
RegressionPartitionedLinear kfoldLoss, kfoldPredict
Neural network regression model RegressionNeuralNetwork, CompactRegressionNeuralNetwork loss, predict, resubLoss, resubPredict
RegressionPartitionedNeuralNetwork kfoldLoss, kfoldPredict
Support vector machine (SVM) regression model RegressionSVM, CompactRegressionSVM loss, predict, resubLoss, resubPredict
RegressionPartitionedSVM kfoldLoss, kfoldPredict

In previous releases, the regression model loss and predict functions listed above used NaN predicted response values for observations with missing predictor values. The software omitted observations with missing predictor values from the resubstitution ("resub") and cross-validation ("kfold") computations for prediction and loss.

Starting in R2023a, predict fully supports GPU arrays.