Classification edge for Gaussian kernel classification model

`e = edge(Mdl,X,Y)`

`e = edge(Mdl,X,Y,'Weights',weights)`

returns the classification
edge for the binary Gaussian kernel classification model
`e`

= edge(`Mdl`

,`X`

,`Y`

)`Mdl`

using the predictor data in `X`

and
the corresponding class labels in `Y`

.

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`

Partition the data set into training and test sets. Specify a 15% holdout sample for the test set.

rng('default') % For reproducibility Partition = cvpartition(Y,'Holdout',0.15); trainingInds = training(Partition); % Indices for the training set testInds = test(Partition); % Indices for the test set

Train a binary kernel classification model using the training set.

Mdl = fitckernel(X(trainingInds,:),Y(trainingInds));

Estimate the training-set edge and the test-set edge.

eTrain = edge(Mdl,X(trainingInds,:),Y(trainingInds))

eTrain = 2.1703

eTest = edge(Mdl,X(testInds,:),Y(testInds))

eTest = 1.5643

Perform feature selection by comparing test-set edges from multiple models. Based solely on this criterion, the classifier with the highest edge is the best classifier.

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`

Partition the data set into training and test sets. Specify a 15% holdout sample for the test set.

rng('default') % For reproducibility Partition = cvpartition(Y,'Holdout',0.15); trainingInds = training(Partition); % Indices for the training set XTrain = X(trainingInds,:); YTrain = Y(trainingInds); testInds = test(Partition); % Indices for the test set XTest = X(testInds,:); YTest = Y(testInds);

Randomly choose half of the predictor variables.

```
p = size(X,2); % Number of predictors
idxPart = randsample(p,ceil(0.5*p));
```

Train two binary kernel classification models: one that uses all of the predictors, and one that uses half of the predictors.

Mdl = fitckernel(XTrain,YTrain); PMdl = fitckernel(XTrain(:,idxPart),YTrain);

`Mdl`

and `PMdl`

are `ClassificationKernel`

models.

Estimate the test-set edge for each classifier.

fullEdge = edge(Mdl,XTest,YTest)

fullEdge = 1.6335

partEdge = edge(PMdl,XTest(:,idxPart),YTest)

partEdge = 2.0205

Based on the test-set edges, the classifier that uses half of the predictors is the better model.

`Mdl`

— Binary kernel classification model`ClassificationKernel`

model objectBinary kernel classification model, specified as a `ClassificationKernel`

model object. You can create a
`ClassificationKernel`

model object using `fitckernel`

.

`Y`

— Class labelscategorical array | character array | string array | logical vector | numeric vector | cell array of character vectors

Class labels, specified as a categorical, character, or string array, logical or numeric vector, or cell array of character vectors.

The data type of

`Y`

must be the same as the data type of`Mdl.ClassNames`

. (The software treats string arrays as cell arrays of character vectors.)The distinct classes in

`Y`

must be a subset of`Mdl.ClassNames`

.If

`Y`

is a character array, then each element must correspond to one row of the array.The length of

`Y`

and the number of observations in`X`

must be equal.

**Data Types: **`categorical`

| `char`

| `string`

| `logical`

| `single`

| `double`

| `cell`

`weights`

— Observation weightspositive numeric vector

Observation weights, specified as a positive numeric vector of length
* n*, where

`n`

`X`

. If you supply weights,
`edge`

computes the weighted classification edge.The default value is
`ones(`

.* n*,1)

`edge`

normalizes `weights`

to
sum up to the value of the prior probability in the respective class.

**Data Types: **`double`

| `single`

`e`

— Classification edgenumeric scalar

Classification edge, returned as a numeric scalar.

The *classification edge* is
the weighted mean of the *classification margins*.

One way to choose among multiple classifiers, for example to perform feature selection, is to choose the classifier that yields the greatest edge.

The *classification margin* for binary classification
is, for each observation, the difference between the classification score for the true class
and the classification score for the false class.

The software defines the classification margin for binary classification as

$$m=2yf\left(x\right).$$

*x* is an observation. If the true label of
*x* is the positive class, then *y* is 1, and –1
otherwise. *f*(*x*) is the positive-class classification
score for the observation *x*. The classification margin is commonly
defined as *m* =
*y**f*(*x*).

If the margins are on the same scale, then they serve as a classification confidence measure. Among multiple classifiers, those that yield greater margins are better.

For kernel classification models, the raw *classification
score* for classifying the observation *x*, a row vector,
into the positive class is defined by

$$f\left(x\right)=T(x)\beta +b.$$

$$T(\xb7)$$ is a transformation of an observation for feature expansion.

*β*is the estimated column vector of coefficients.*b*is the estimated scalar bias.

The raw classification score for classifying *x* into the negative class is −*f*(*x*). The software classifies observations into the class that yields a
positive score.

If the kernel classification model consists of logistic regression learners, then the
software applies the `'logit'`

score transformation to the raw
classification scores (see `ScoreTransform`

).

Calculate with arrays that have more rows than fit in memory.

This function fully supports tall arrays. For more information, see Tall Arrays (MATLAB).

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

Select web siteYou can also select a web site from the following list:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

- América Latina (Español)
- Canada (English)
- United States (English)

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)