ClassificationPartitionedModel
statistics: ClassificationPartitionedModel
Cross-validated classification model
The ClassificationPartitionedModel class stores cross-validated
classification models trained on different partitions of the data.
It can predict responses for observations not used for training using
the kfoldPredict method.
Create a ClassificationPartitionedModel object by using the
crossval function.
See also: crossval
Source Code: ClassificationPartitionedModel
A cell array specifying the bin edges for binned predictors. This property is read-only.
A vector of positive integers specifying the indices of categorical predictors. This property is read-only.
A numeric matrix containing the unstandardized predictor data. Each column of X represents one predictor (variable), and each row represents one observation. This property is read-only.
Specified as a logical or numeric column vector, or as a character array or a cell array of character vectors with the same number of rows as the predictor data. Each row in Y is the observed class label for the corresponding row in X. This property is read-only.
An array of unique values of the response variable Y, which has the
same data types as the data in Y. This property is read-only.
ClassNames can have any of the following datatypes:
A square matrix specifying the cost of misclassification of a point.
Cost(i,j) is the cost of classifying a point into class j
if its true class is i (that is, the rows correspond to the true
class and the columns correspond to the predicted class). The order of
the rows and columns in Cost corresponds to the order of the
classes in ClassNames. The number of rows and columns in
Cost is the number of unique classes in the response. By
default, Cost(i,j) = 1 if i != j, and
Cost(i,j) = 0 if i = j. In other words, the cost is 0
for correct classification and 1 for incorrect classification.
A character vector specifying the class of the cross-validated model.
This field contains the type of model that was used for the training,
e.g., "ClassificationKNN". This property is read-only.
A positive integer value specifying the number of cross-validated folds. This property is read-only.
A structure containing the model parameters used during training. This includes any model-specific parameters that were configured prior to training. This property is read-only.
A positive integer value specifying the number of observations in the training dataset used for training the cross-validated model. This property is read-only.
A cvpartition object specifying the partition configuration used
for cross-validation. This field stores the cvpartition instance that
describes how the data was split into training and validation sets.
This property is read-only.
A cell array of character vectors specifying the names of the predictor variables. The names are in the order in which the appear in the training dataset. This property is read-only.
A numeric vector specifying the prior probabilities for each class. The
order of the elements in Prior corresponds to the order of the
classes in ClassNames. This property is read-only.
A character vector specifying the name of the response variable Y. This property is read-only.
Specified as a function handle for transforming the classification scores. This property is read-only.
A logical scalar specifying whether to standardize the predictors. This property is read-only.
A cell array of models trained on each fold. Each cell contains a model trained on the minus-one fold of the data (all but one fold used for training and the remaining fold used for validation). This property is read-only.
ClassificationPartitionedModel: this = ClassificationPartitionedModel (Mdl, Partition)
this = ClassificationPartitionedModel (Mdl,
Partition) returns a ClassificationPartitionedModel object, with
Mdl as the trained classification model object and
Partition as the partitioning object obtained using cvpartition
function.
See also: cvpartition
ClassificationPartitionedModel: label = kfoldPredict (this)
ClassificationPartitionedModel: [label, score, cost] = kfoldPredict (this)
[label, Score, Cost] = kfoldPredict (this)
returns the predicted class labels, classification scores, and
classification costs for the data used
to train the cross-validated model this.
this is a ClassificationPartitionedModel object.
The function predicts the response for each observation that was
held out during training in the cross-validation process.
| Output | Description | |
|---|---|---|
label | Predicted class labels, returned as a vector or cell array. The type of label matches the type of Y in the original training data. Each element of label corresponds to the predicted class label for the corresponding row in X. | |
Score | Classification scores, returned as a numeric matrix. Each row of Score corresponds to an observation, and each column corresponds to a class. The value in row i and column j is the classification score for class j for observation i. | |
Cost | Classification costs, returned as a numeric matrix. Each row of Cost corresponds to an observation, and each column corresponds to a class. The value in row i and column j is the classification cost for class j for observation i. This output is optional and only returned if requested. |
See also: ClassificationKNN, ClassificationSVM, ClassificationPartitionedModel
load fisheriris x = meas; y = species; ## Create a KNN classifier model obj = fitcknn (x, y, "NumNeighbors", 5, "Standardize", 1); ## Create a partition for 5-fold cross-validation partition = cvpartition (y, "KFold", 5); ## Create the ClassificationPartitionedModel object cvModel = crossval (obj, 'cvPartition', partition) |
cvModel =
ClassificationPartitionedModel object with properties:
BinEdges: []
CategoricalPredictors: []
X: [5.1000, 3.5000, 1.4000, 0.2000; 4.9000, 3, 1.4000, 0.2000; 4.7000, 3.2000, ...]
Y: [150x1 cell]
ClassNames: [3x1 cell]
Cost: [0, 1, 1; 1, 0, 1; 1, 1, 0]
CrossValidatedModel: 'ClassificationKNN'
KFold: 5
ModelParameters: [1x1 struct]
NumObservations: 150
Partition: [1x1 cvpartition]
PredictorNames: [1x4 cell]
Prior: [0.3333; 0.3333; 0.3333]
ResponseName: "Y"
ScoreTransform: [1x1 function_handle]
Standardize: 1
Trained: [5x1 cell]
|
load fisheriris
x = meas;
y = species;
## Create a KNN classifier model
obj = fitcknn (x, y, "NumNeighbors", 5, "Standardize", 1);
## Create the ClassificationPartitionedModel object
cvModel = crossval (obj);
## Predict the class labels for the observations not used for training
[label, score, cost] = kfoldPredict (cvModel);
fprintf ("Cross-validated accuracy = %1.2f%% (%d/%d)\n", ...
sum (strcmp (label, y)) / numel (y) *100, ...
sum (strcmp (label, y)), numel (y)) |
Cross-validated accuracy = 96.67% (145/150) |