ClassificationPartitionedModel
Package: classreg.learning.partition
Crossvalidated classification model
Description
ClassificationPartitionedModel
is a set of
classification models trained on crossvalidated folds. Estimate the quality of
classification by cross validation using one or more “kfold” methods:
kfoldPredict
, kfoldLoss
, kfoldMargin
, kfoldEdge
, and kfoldfun
.
Every “kfold” method uses models trained on infold observations to predict the response for outoffold observations. For example, suppose you cross validate using five folds. In this case, the software randomly assigns each observation into five roughly equally sized groups. The training fold contains four of the groups (i.e., roughly 4/5 of the data) and the test fold contains the other group (i.e., roughly 1/5 of the data). In this case, cross validation proceeds as follows:
The software trains the first model (stored in
CVMdl.Trained{1}
) using the observations in the last four groups and reserves the observations in the first group for validation.The software trains the second model (stored in
CVMdl.Trained{2}
) using the observations in the first group and last three groups, and reserves the observations in the second group for validation.The software proceeds in a similar fashion for the third to fifth models.
If you validate by calling kfoldPredict
, it computes predictions for
the observations in group 1 using the first model, group 2 for the second model, and so
on. In short, the software estimates a response for every observation using the model
trained without that observation.
Construction
creates a crossvalidated classification model from a classification model
(CVMdl
=
crossval(Mdl
)Mdl
).
Alternatively:
CVDiscrMdl = fitcdiscr(X,Y,Name,Value)
CVKNNMdl = fitcknn(X,Y,Name,Value)
CVNetMdl = fitcnet(X,Y,Name,Value)
CVNBMdl = fitcnb(X,Y,Name,Value)
CVSVMMdl = fitcsvm(X,Y,Name,Value)
CVTreeMdl = fitctree(X,Y,Name,Value)
create a crossvalidated model when Name
is either
'CrossVal'
, 'KFold'
,
'Holdout'
, 'Leaveout'
, or
'CVPartition'
. For syntax details, see fitcdiscr
, fitcknn
, fitcnet
,
fitcnb
, fitcsvm
, and fitctree
.
Input Arguments

A classification model, specified as one of the following:

Properties

Bin edges for numeric predictors, specified as a cell array of p numeric vectors, where p is the number of predictors. Each vector includes the bin edges for a numeric predictor. The element in the cell array for a categorical predictor is empty because the software does not bin categorical predictors. The software bins numeric predictors only if you specify the You can reproduce the binned predictor data X = mdl.X; % Predictor data
Xbinned = zeros(size(X));
edges = mdl.BinEdges;
% Find indices of binned predictors.
idxNumeric = find(~cellfun(@isempty,edges));
if iscolumn(idxNumeric)
idxNumeric = idxNumeric';
end
for j = idxNumeric
x = X(:,j);
% Convert x to array if x is a table.
if istable(x)
x = table2array(x);
end
% Group x into bins by using the Xbinned
contains the bin indices, ranging from 1 to the number of bins, for numeric predictors.
Xbinned values are 0 for categorical predictors. If
X contains NaN s, then the corresponding
Xbinned values are NaN s.
 

Categorical predictor indices, specified
as a vector of positive integers. Assuming that the predictor data contains
observations in rows, If  
 Unique class labels used in training the model, specified as a categorical or character array, logical or numeric vector, or cell array of character vectors.  

Square matrix, where If CVModel.Cost = CostMatrix;  

Name of the crossvalidated model, which is a character vector.  

Number of folds used in crossvalidated model, which is a positive integer.  

Object holding parameters of  

Number of observations in the training data stored in
 

The partition of class  
 Predictor variable names, specified as a cell array of character vectors. The order of the
elements in  

Numeric vector of prior probabilities for each class. The order of the
elements of If CVModel.Prior = priorVector;  
 Response variable name, specified as a character vector.  

Score transformation, specified as a character vector or function handle. To change the score transformation function to
 

The trained learners, which is a cell array of compact classification models.  

The scaled  

A matrix or table of predictor values.  

Categorical or character array, logical or numeric vector, or cell array
of character vectors specifying the class labels for each observation. Each
entry of 
Object Functions
gather  Gather properties of Statistics and Machine Learning Toolbox object from GPU 
kfoldEdge  Classification edge for crossvalidated classification model 
kfoldLoss  Classification loss for crossvalidated classification model 
kfoldMargin  Classification margins for crossvalidated classification model 
kfoldPredict  Classify observations in crossvalidated classification model 
kfoldfun  Crossvalidate function for classification 
Copy Semantics
Value. To learn how value classes affect copy operations, see Copying Objects.
Examples
Tips
To estimate posterior probabilities of trained, crossvalidated SVM classifiers, use
fitSVMPosterior
.