RegressionPartitionedKernel
statistics: RegressionPartitionedKernel
Cross-validated Gaussian kernel regression model.
A RegressionPartitionedKernel object holds one
RegressionKernel per fold of a partition, each fitted to the
observations the fold trains on. kfoldPredict predicts each
observation with the fold that held it out, so what it returns is
an out-of-sample prediction.
A RegressionKernel stores no copy of its training data and so has
no resubstitution methods and no compact form. This class is what
takes their place: cross-validation is the way a kernel model is asked
how it would do on data it has not seen.
Every fold draws its own random basis, as it must, being its own fit.
Two folds therefore approximate the same kernel through different
expansions, which is a source of variation between folds over and above
the data they were given. A larger 'NumExpansionDimensions'
narrows it.
Create one with fitrlinear and a cross-validation option, or
directly.
See also: fitrlinear, RegressionKernel, RegressionPartitionedKernel
Source Code: RegressionPartitionedKernel
The RegressionPartitionedKernel class contains the following properties:
A character vector, or the text of the function handle that was supplied, which may be assigned after the model is built. The fold models carry no transform of their own; this one is applied once to the assembled predictions.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 64.938
Always 'Linear', the short name MATLAB uses. This property is
read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 65.766
A positive integer scalar, counting the rows that survived the removal of missing values. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 64.637
An numeric vector. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 71.217
An numeric vector summing to one. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 65.854
A cell array of character vectors. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 68.702
A row vector of column indices, empty when every predictor is numeric. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 66.942
A character vector, defaulting to 'Y'. This property is
read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 65.598
A cell column with one RegressionKernel per fold, each fitted
to the observations its fold trains on. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 67.267
A positive integer scalar. A holdout partition has one fold and a leave-one-out partition has as many as there are observations. This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 67.851
A cvpartition object over the retained observations. This
property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 73.863
A structure holding the parameters the folds were fitted with, carried
through from the learner that was cross validated, beside
NLearn, the number of folds, and the Version,
Method and Type tags of this class, with
LearnerTemplates naming the backing. The
learner’s own tags are replaced rather than kept, so a cross-validated
SVM reports Method as 'PartitionedKernel' and not
'SVM'.
Deviation from MATLAB. MATLAB reports the parameter record of
the cross-validation ensemble here rather than of the learner,
so it says nothing at all about how the folds were fitted: of its
eighteen fields only the fold count, its partitioner and a fit template
carry anything, and the rest are boosting settings left inert. Nor can
the parameters be reached through the folds, a compact model carrying
none in MATLAB. This class reports the fit instead, which is strictly
more than MATLAB offers, and everything MATLAB’s record does carry is
published here as the KFold, Partition, X,
Y, W and CrossValidatedModel properties.
This property is read-only.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 64.890
The RegressionPartitionedKernel class offers the following public methods:
RegressionPartitionedKernel: obj = RegressionPartitionedKernel (X, Y)
RegressionPartitionedKernel: obj = RegressionPartitionedKernel (…, name, value)
obj = RegressionPartitionedKernel (X, Y)
partitions the data into ten folds and fits a
RegressionKernel to each.
obj = RegressionPartitionedKernel (…, name,
value) takes one of 'KFold', 'Holdout',
'Leaveout' and 'CVPartition' to say how to partition,
and any option RegressionKernel takes to say how to fit.
'CrossVal' is accepted and has no effect here, this class
being cross-validated by construction.
Anything left as 'auto' is resolved by each fold against its
own training rows rather than once over the whole data, so ten folds
of a hundred observations each get a Lambda of one ninetieth
rather than one hundredth, and each its own Epsilon and
KernelScale. Both are MATLAB’s behaviour, measured.
See also: fitrlinear, RegressionKernel
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 65.811
RegressionPartitionedKernel: yFit = kfoldPredict (obj)
Each observation is predicted by the fold that held it out, so the
predictions are out-of-sample. An observation that no fold held out,
which under a holdout partition is most of them, comes back
NaN.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 70.171
RegressionPartitionedKernel: l = kfoldLoss (obj)
RegressionPartitionedKernel: l = kfoldLoss (…, name, value)
l = kfoldLoss (obj) returns the out-of-fold mean
squared error.
l = kfoldLoss (…, name, value) takes
'LossFun', either 'mse' or
'epsiloninsensitive'; 'Folds', a subset of the folds
to average over; and 'Mode', either 'average', the
default, or 'individual', which returns one row per fold.
Cross-validate a Gaussian kernel regression of fuel consumption and read the out-of-sample mean squared error.
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 66.470
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedKernel (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedKernel
CrossValidatedModel: 'Kernel'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 69.403