ClassificationPartitionedLinear
statistics: ClassificationPartitionedLinear
Cross-validated linear binary classifier.
A ClassificationPartitionedLinear object holds one
ClassificationLinear per fold of a partition, each fitted to the
observations the fold trains on. Every kfold method predicts each
observation with the fold that held it out, so the estimate it
returns is an out-of-sample one.
A ClassificationLinear 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, every method
returns one column per strength, in the order of the 'Lambda'
that was asked for.
Create one with fitclinear and a cross-validation option, or
directly.
See also: fitclinear, ClassificationLinear, ClassificationPartitionedKernel
Source Code: ClassificationPartitionedLinear
The ClassificationPartitionedLinear class contains the following properties:
A column of the same type as the response, shared by every fold. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.050000
A square numeric matrix with one row and one column per class. It is handed to every fold rather than re-derived by each. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.040000
A numeric row vector summing to one, in the order of
ClassNames. Like the cost it is the parent’s and is handed to
every fold, so a fold of an unbalanced problem does not quietly adopt
a prior of its own. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.060000
A character vector naming a transformation, or the text of the
function handle that was supplied, which may be assigned after the
model is built. It is applied once to the assembled scores and is
not handed to the folds. A transform the learner implies, as
'logistic' implies 'logit', does stay with the folds,
and this one is then applied on top of it.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
Always 'Linear', the short name MATLAB uses. This property is
read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
A positive integer scalar, counting the rows that survived the removal of missing values. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
In the type it was supplied in. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
An numeric vector summing to one, normalized within each class to that class’s cost-adjusted prior. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
A cell array of character vectors. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.020000
A row vector of column indices, empty when every predictor is numeric. This property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.040000
A character vector, defaulting to 'Y'. This property is
read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
A cell column with one ClassificationLinear per fold, each
fitted to the observations its fold trains on. This property is
read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
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 classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.040000
A cvpartition object over the retained observations. This
property is read-only.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 1.0000e-02
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 classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.060000
The ClassificationPartitionedLinear class offers the following public methods:
ClassificationPartitionedLinear: obj = ClassificationPartitionedLinear (X, Y)
ClassificationPartitionedLinear: obj = ClassificationPartitionedLinear (…, name, value)
obj = ClassificationPartitionedLinear (X, Y)
partitions the data into ten stratified folds and fits a
ClassificationLinear to each.
obj = ClassificationPartitionedLinear (…,
name, value) takes one of 'KFold',
'Holdout', 'Leaveout' and 'CVPartition' to say
how to partition, and any option ClassificationLinear takes to
say how to fit. 'CrossVal' is accepted and has no effect
here, this class being cross-validated by construction.
The classes, the prior and the cost are resolved once over the whole
data and handed to every fold. Anything left as 'auto' is
not: each fold resolves 'Lambda' against its own training
rows, so ten folds of a hundred observations each get one ninetieth
rather than one hundredth. Both are MATLAB’s behaviour, measured.
See also: fitclinear, ClassificationLinear
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
ClassificationPartitionedLinear: labels = kfoldPredict (obj)
ClassificationPartitionedLinear: [labels, scores] = kfoldPredict (obj)
Each observation is classified by the fold that held it out, so the
labels are out-of-sample. An observation that no fold held out, which
under a holdout partition is most of them, comes back missing rather
than classified, and its scores come back NaN.
With regularization strengths labels has one column per strength and scores is .
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.050000
ClassificationPartitionedLinear: m = kfoldMargin (obj)
The score the out-of-fold model gives the true class, less the score
it gives the other one. An observation no fold held out comes back
NaN. With regularization strengths m has one
column per strength.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
ClassificationPartitionedLinear: e = kfoldEdge (obj)
ClassificationPartitionedLinear: e = kfoldEdge (…, name, value)
e = kfoldEdge (…, name, value) takes
'Folds', a subset of the folds to average over, and
'Mode', either 'average', the default, or
'individual', which returns one row per fold instead.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.050000
ClassificationPartitionedLinear: l = kfoldLoss (obj)
ClassificationPartitionedLinear: l = kfoldLoss (…, name, value)
l = kfoldLoss (obj) returns the out-of-fold
misclassification rate.
l = kfoldLoss (…, name, value) takes
'LossFun', one of 'binodeviance',
'classifcost', 'classiferror', 'exponential',
'hinge', 'logit', 'mincost' and
'quadratic'; 'Folds'; and 'Mode'.
Cross-validate a linear classifier on the two overlapping iris species and read the out-of-sample error rate.
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000
load fisheriris X = meas(51:end,:); Y = species(51:end); CVMdl = ClassificationPartitionedLinear (X, Y, 'KFold', 5)
CVMdl =
ClassificationPartitionedLinear
CrossValidatedModel: 'Linear'
ClassNames: {'versicolor' 'virginica'}
ScoreTransform: 'none'
NumObservations: 100
KFold: 5
outOfSample = kfoldLoss (CVMdl)
outOfSample = 0.030000