This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

ClassificationPartitionedKernel

Cross-validated, binary kernel classification model

Description

ClassificationPartitionedKernel is a binary kernel classification model, trained on cross-validated folds. You can estimate the quality of classification, or how well the kernel classification model generalizes, using one or more “kfold” functions: kfoldPredict, kfoldLoss, kfoldMargin, and kfoldEdge.

Every “kfold” method uses models trained on training-fold (in-fold) observations to predict the response for validation-fold (out-of-fold) observations. For example, suppose that you cross-validate using five folds. In this case, the software randomly assigns each observation into five groups of equal size (roughly). The training fold contains four of the groups (that is, roughly 4/5 of the data) and the validation fold contains the other group (that is, roughly 1/5 of the data). In this case, cross-validation proceeds as follows:

  1. The software trains the first model (stored in CVMdl.Trained{1}) by using the observations in the last four groups and reserves the observations in the first group for validation.

  2. The software trains the second model (stored in CVMdl.Trained{2}) using the observations in the first group and the last three groups. The software reserves the observations in the second group for validation.

  3. The software proceeds in a similar fashion for the third, fourth, and fifth models.

If you validate by using kfoldPredict, the software computes predictions for the observations in group i by using the ith model. In short, the software estimates a response for every observation by using the model trained without that observation.

Note

ClassificationPartitionedKernel model objects do not store the predictor data set.

Creation

You can create a ClassificationPartitionedKernel model by training a classification kernel model using fitckernel and specifying one of these name-value pair arguments: 'Crossval', 'CVPartition', 'Holdout', 'KFold', or 'Leaveout'.

Properties

expand all

Cross-Validation Properties

This property is read-only.

Cross-validated model name, specified as a character vector.

For example, 'Kernel' specifies a cross-validated kernel model.

Data Types: char

This property is read-only.

Number of cross-validated folds, specified as a positive integer scalar.

Data Types: double

This property is read-only.

Cross-validation parameter values, specified as an object. The parameter values correspond to the name-value pair argument values used to cross-validate the kernel classifier. ModelParameters does not contain estimated parameters.

You can access the properties of ModelParameters using dot notation.

This property is read-only.

Number of observations in the training data, specified as a positive numeric scalar.

Data Types: double

This property is read-only.

Data partition indicating how the software splits the data into cross-validation folds, specified as a cvpartition model.

This property is read-only.

Kernel classifiers trained on cross-validation folds, specified as a cell array of ClassificationKernel models. Trained has k cells, where k is the number of folds.

Data Types: cell

This property is read-only.

Observation weights used to cross-validate the model, specified as a numeric vector. W has NumObservations elements.

The software normalizes the weights used for training so that nansum(W) is 1.

Data Types: single | double

This property is read-only.

Observed class labels used to cross-validate the model, specified as a categorical or character array, logical or numeric vector, or cell array of character vectors. Y has NumObservations elements and has the same data type as the input argument Y that you pass to fitckernel to cross-validate the model. (The software treats string arrays as cell arrays of character vectors.)

Each row of Y represents the observed classification of the corresponding row of X.

Data Types: categorical | char | logical | single | double | cell

Other Classification Properties

This property is read-only.

Categorical predictor indices, specified as an empty numeric value. In general, CategoricalPredictors contains index values corresponding to the columns of the predictor data that contain categorical predictors. Because ClassificationKernel models can be trained on numeric predictor data only, this property is empty ([]).

This property is read-only.

Unique class labels used in training, specified as a categorical or character array, logical or numeric vector, or cell array of character vectors. ClassNames has the same data type as the observed class labels property Y and determines the class order.

Data Types: categorical | char | logical | single | double | cell

This property is read-only.

Misclassification costs, specified as a square numeric matrix. Cost has K rows and columns, where K is the number of classes.

Cost(i,j) is the cost of classifying a point into class j if its true class is i. The order of the rows and columns of Cost corresponds to the order of the classes in ClassNames.

Data Types: double

This property is read-only.

Predictor names in order of their appearance in the predictor data X, specified as a cell array of character vectors of the form {'x1','x2',...}. The length of PredictorNames is equal to the number of columns in X.

Data Types: cell

This property is read-only.

Prior class probabilities, specified as a numeric vector. Prior has as many elements as there are classes in ClassNames, and the order of the elements corresponds to the elements of ClassNames.

Data Types: double

This property is read-only.

Response variable name, specified as 'Y'. Because ClassificationKernel models cannot be trained on tabular data, this property is always 'Y'.

Data Types: char

Score transformation function to apply to predicted scores, specified as a function name or function handle.

For a kernel classification model Mdl, and before the score transformation, the predicted classification score for the observation x (row vector) is f(x)=T(x)β+b.

  • T(·) is a transformation of an observation for feature expansion.

  • β is the estimated column vector of coefficients.

  • b is the estimated scalar bias.

To change the CVMdl score transformation function to function, for example, use dot notation.

  • For a built-in function, enter this code and replace function with a value from the table.

    CVMdl.ScoreTransform = 'function';

    ValueDescription
    'doublelogit'1/(1 + e–2x)
    'invlogit'log(x / (1 – x))
    'ismax'Sets the score for the class with the largest score to 1, and sets the scores for all other classes to 0
    'logit'1/(1 + ex)
    'none' or 'identity'x (no transformation)
    'sign'–1 for x < 0
    0 for x = 0
    1 for x > 0
    'symmetric'2x – 1
    'symmetricismax'Sets the score for the class with the largest score to 1, and sets the scores for all other classes to –1
    'symmetriclogit'2/(1 + ex) – 1

  • For a MATLAB® function or a function that you define, enter its function handle.

    CVMdl.ScoreTransform = @function;

    function must accept a matrix of the original scores for each class, and then return a matrix of the same size representing the transformed scores for each class.

Data Types: char | function_handle

Object Functions

kfoldEdgeClassification edge for cross-validated kernel classification model
kfoldLossClassification loss for cross-validated kernel classification model
kfoldMarginClassification margins for cross-validated kernel classification model
kfoldPredictClassify observations in cross-validated kernel classification model

Examples

collapse all

Load the ionosphere data set. This data set has 34 predictors and 351 binary responses for radar returns, either bad ('b') or good ('g').

load ionosphere
rng('default') % For reproducibility

Cross-validate a binary kernel classification model. By default, the software uses 10-fold cross-validation.

CVMdl = fitckernel(X,Y,'CrossVal','on')
CVMdl = 
  classreg.learning.partition.ClassificationPartitionedKernel
    CrossValidatedModel: 'Kernel'
           ResponseName: 'Y'
        NumObservations: 351
                  KFold: 10
              Partition: [1x1 cvpartition]
             ClassNames: {'b'  'g'}
         ScoreTransform: 'none'


  Properties, Methods

numel(CVMdl.Trained)
ans = 10

CVMdl is a ClassificationPartitionedKernel model. Because fitckernel implements 10-fold cross-validation, CVMdl contains 10 ClassificationKernel models that the software trains on training-fold (in-fold) observations.

Estimate the cross-validated classification error.

kfoldLoss(CVMdl)
ans = 0.0940

The classification error rate is approximately 9%.

Introduced in R2018b