fitrsvm
statistics: Mdl = fitrsvm (X, Y)
statistics: Mdl = fitrsvm (…, name, value)
Fit a support vector machine regression model.
Mdl = fitrsvm (X, Y) returns a support vector
regression model, Mdl, with X being the predictor data and
Y the continuous response of the observations in X.
The model is fitted by -insensitive regression: an error
smaller than Epsilon costs nothing, so only the observations
outside that tube become support vectors. Use fitcsvm where the
response names a class rather than a quantity.
Mdl = fitrsvm (…, name, value) returns a
model with additional options specified by Name-Value pair
arguments listed below.
| Name | Value |
|---|---|
'Standardize' | A logical scalar indicating whether the
data in X should be centred and scaled before training. The same
transformation is applied by predict. The default is false. |
'PredictorNames' | A cell array of character vectors specifying the predictor variable names, in the order they appear in X. |
'ResponseName' | A character vector specifying the name of
the response variable. The default is 'Y'. |
'ResponseTransform' | A character vector naming one of
'none', 'identity', 'exp' or 'log', or a
function handle of one argument, applied to the predicted response. The
default is 'none'. |
'Epsilon' | A non-negative scalar, the half-width of the
insensitive tube. The default is iqr (Y) / 13.49, a robust
estimate of a tenth of the response’s standard deviation, which is what
MATLAB uses; where that is zero it falls back to . |
'BoxConstraint' | A positive scalar bounding the dual coefficients, the cost of an error outside the tube. The default is 1. |
'KernelFunction' | A character vector naming the kernel,
one of 'linear', the default, 'rbf', 'gaussian',
'polynomial' or 'sigmoid'. |
'PolynomialOrder' | A positive integer, the order of the polynomial kernel. The default is 3. It is ignored by every other kernel. |
'KernelScale' | A positive scalar dividing the predictors before the kernel is applied. The default is 1. |
'KernelOffset' | A non-negative scalar added to the kernel value. The default is 0. |
'SVMtype' | A character vector selecting the formulation,
either 'eps_svr', the default, or 'nu_svr'. MATLAB fits
only the form; 'nu_svr' is an Octave extension. |
'Nu' | A scalar in used by
'nu_svr', bounding the fraction of support vectors. The default
is 0.5. |
'CacheSize' | A positive scalar, the kernel cache in megabytes. The default is 1000. |
'Tolerance' | A non-negative scalar, the tolerance of the termination criterion. The default is . |
'Shrinking' | Either 0 or 1, whether to use the shrinking heuristic. The default is 1. |
Source Code: fitrsvm
See also: RegressionSVM, fitcsvm, fitrnet, svmtrain, svmpredict
Source Code: fitrsvm
load carsmall X = [Horsepower, Weight]; Mdl = fitrsvm (X, MPG, 'Standardize', true);
Rows carrying a missing value were dropped, so ask about the ones used
used = Mdl.RowsUsed;
yFit = predict (Mdl, X(used,:));
plot (MPG(used), yFit, 'o', [5, 45], [5, 45], 'k-');
axis equal;
xlabel ('Observed MPG');
ylabel ('Predicted MPG');
title (sprintf ('Linear SVR, RMSE %.2f', sqrt (resubLoss (Mdl))));
Errors smaller than Epsilon cost nothing, so a wider tube is fitted by fewer observations and a narrower one by almost all of them.
load carsmall
X = [Horsepower, Weight];
eps_ = [0.1, 0.5, 1, 2, 4, 8];
nsv = zeros (size (eps_));
for k = 1:numel (eps_)
m = fitrsvm (X, MPG, 'Standardize', true, 'Epsilon', eps_(k));
nsv(k) = sum (m.IsSupportVector);
endfor
plot (eps_, nsv, 'o-', 'linewidth', 1.5);
xlabel ('Epsilon');
ylabel ('Number of support vectors');
title ('A wider tube needs fewer support vectors');
rand ('seed', 7);
randn ('seed', 7);
x = linspace (-3, 3, 120)';
y = sin (x) + randn (120, 1) * 0.1;
lin = fitrsvm (x, y);
rbf = fitrsvm (x, y, 'KernelFunction', 'rbf', 'BoxConstraint', 10);
plot (x, y, 'o', 'markersize', 4);
hold on;
plot (x, predict (lin, x), 'k--', 'linewidth', 1.5);
plot (x, predict (rbf, x), 'r-', 'linewidth', 2);
hold off;
legend ({'data', 'linear kernel', 'rbf kernel'});
title ('Support vector regression');
load carsmall
X = [Horsepower, Weight];
Mdl = fitrsvm (X, MPG, 'Standardize', true);
used = Mdl.RowsUsed;
Xs = (X(used,:) - Mdl.Mu) ./ Mdl.Sigma;
printf ('max |X*Beta + Bias - predict| = %g\n', ...
max (abs (Xs * Mdl.Beta + Mdl.Bias - resubPredict (Mdl))));
max |X*Beta + Bias - predict| = 2.84217e-14