fitrkernel
statistics: Mdl = fitrkernel (X, Y)
statistics: Mdl = fitrkernel (Tbl, ResponseVarName)
statistics: Mdl = fitrkernel (Tbl, formula)
statistics: Mdl = fitrkernel (Tbl, Y)
statistics: Mdl = fitrkernel (…, name, value)
statistics: [Mdl, FitInfo] = fitrkernel (…)
Fit a Gaussian kernel regression model.
Mdl = fitrkernel (X, Y) returns a
RegressionKernel object fitted to the predictor data X and
the continuous response Y, where X is an NxP numeric
matrix and Y an Nx1 numeric vector with as many rows as
X.
Mdl = fitrkernel (…, name, value) passes
the given Name-Value pairs to the model. They are documented
under RegressionKernel, and the ones most often wanted are
'Learner', 'Epsilon',
'NumExpansionDimensions', 'KernelScale',
'Lambda' and 'BoxConstraint'.
[Mdl, FitInfo] = fitrkernel (…) also returns a
structure describing the optimization: the objective it reached, the
gradient it left, and the tolerances it was given.
Mdl = fitrkernel (…, cvopt, value) returns a
RegressionPartitionedKernel
instead when one of 'CrossVal', 'KFold',
'Holdout', 'Leaveout' and 'CVPartition' is
given. A cross-validated model describes no single fit, so
FitInfo is not available beside it.
See also: RegressionKernel, RegressionLinear, fitrlinear
Source Code: fitrkernel
Fit a Gaussian kernel regression to fuel consumption and read what the optimization did.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); [Mdl, FitInfo] = fitrkernel (X(ok,:), MPG(ok))
Mdl =
RegressionKernel
ResponseName: 'Y'
Learner: 'svm'
NumExpansionDimensions: 128
KernelScale: 1
Lambda: 0.0107527
BoxConstraint: 1
Epsilon: 0.926612
FitInfo =
scalar structure containing the fields:
Solver = LBFGS-fast
LossFunction = epsiloninsensitive
Lambda = 0.010753
BetaTolerance = 1.0000e-04
GradientTolerance = 1.0000e-06
ObjectiveValue = 5.4015
GradientMagnitude = 2.8793e-03
RelativeChangeInBeta = 7.5894e-05
FitTime = 0
History = [](0x0)
Fit from a table, and predict on one
load fisheriris
T = table (meas(:,2), meas(:,3), meas(:,4), meas(:,1), ...
'VariableNames', {'SW', 'PL', 'PW', 'SL'});
A model formula names the response and the predictors together, and holds main effects only
Mdl = fitrkernel (T, 'SL ~ PL + PW'); Mdl.PredictorNames
ans =
1x2 cell array
{'PL'} {'PW'}
Mdl.ResponseName
ans = SL
predict matches the table's variables by name, so a column the model was not fitted on is passed over
yFit = predict (Mdl, T(1:5,:)); yFit'
ans = 4.9785 4.9785 4.9597 5.0029 4.9785