RegressionPartitionedLinear
statistics: RegressionPartitionedLinear
Cross-validated linear regression model.
A RegressionPartitionedLinear object holds one
RegressionLinear 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 RegressionLinear 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 linear model is asked
how it would do on data it has not seen.
When the fold models carry a whole regularization path, both methods
return one column per strength, in the order of the 'Lambda' that
was asked for.
Create one with fitrlinear and a cross-validation option, or
directly.
See also: fitrlinear, RegressionLinear, RegressionPartitionedKernel
Source Code: RegressionPartitionedLinear
The RegressionPartitionedLinear 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 linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 63.281
Always 'Linear', the short name MATLAB uses. This property is
read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 64.055
A positive integer scalar, counting the rows that survived the removal of missing values. This property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 61.731
An numeric vector. This property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 61.977
An numeric vector summing to one. This property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 63.456
A cell array of character vectors. This property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 61.443
A row vector of column indices, empty when every predictor is numeric. This property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 62.101
A character vector, defaulting to 'Y'. This property is
read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 60.936
A cell column with one RegressionLinear per fold, each fitted
to the observations its fold trains on. This property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 63.416
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 linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 60.559
A cvpartition object over the retained observations. This
property is read-only.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 63.661
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 'PartitionedLinear' 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 linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 61.109
The RegressionPartitionedLinear class offers the following public methods:
RegressionPartitionedLinear: obj = RegressionPartitionedLinear (X, Y)
RegressionPartitionedLinear: obj = RegressionPartitionedLinear (…, name, value)
obj = RegressionPartitionedLinear (X, Y)
partitions the data into ten folds and fits a
RegressionLinear to each.
obj = RegressionPartitionedLinear (…, name,
value) takes one of 'KFold', 'Holdout',
'Leaveout' and 'CVPartition' to say how to partition,
and any option RegressionLinear 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. Both are
MATLAB’s behaviour, measured.
See also: fitrlinear, RegressionLinear
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 65.206
RegressionPartitionedLinear: 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.
With regularization strengths yFit has one column per strength.
Cross-validate a linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 62.920
RegressionPartitionedLinear: l = kfoldLoss (obj)
RegressionPartitionedLinear: 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 linear 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 = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 68.686
load carsmall X = [Acceleration, Displacement, Horsepower, Weight]; ok = ! any (isnan ([X, MPG]), 2); CVMdl = RegressionPartitionedLinear (X(ok,:), MPG(ok), 'KFold', 5)
CVMdl =
RegressionPartitionedLinear
CrossValidatedModel: 'Linear'
ResponseName: 'Y'
ResponseTransform: 'none'
NumObservations: 93
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 67.011