margin - Classification margins for discriminant analysis classifier - MATLAB (original) (raw)

Classification margins for discriminant analysis classifier

Syntax

Description

`m` = margin([Mdl](#bs1qgpm%5Fsep%5Fmw%5F3e32f650-278e-4315-906b-4b212b883c4f),[Tbl](#bs1qgpm%5Fsep%5Fmw%5F61033656-2e21-4771-a0da-bef8c59ac731),[ResponseVarName](#bs1qgpm%5Fsep%5Fmw%5F57b94c1d-62e8-4c7d-a13b-6dcd77d1b6a5)) returns the Classification Margin (m) for the trained discriminant analysis classifier Mdl using the predictor data in tableTbl and the class labels inTbl.ResponseVarName.

`m` = margin([Mdl](#bs1qgpm%5Fsep%5Fmw%5F3e32f650-278e-4315-906b-4b212b883c4f),[Tbl](#bs1qgpm%5Fsep%5Fmw%5F61033656-2e21-4771-a0da-bef8c59ac731),[Y](#bs1qgpm%5Fsep%5Fmw%5F9da41ba9-8cb4-4909-9926-d3ad722ab6f3)) returns the classification margins for Mdl using the predictor data in table Tbl and the class labels in Y.

`m` = margin([Mdl](#bs1qgpm%5Fsep%5Fmw%5F3e32f650-278e-4315-906b-4b212b883c4f),[X](#bs1qgpm%5Fsep%5Fmw%5F5701dad1-05a7-4767-893d-b73a19be843c),[Y](#bs1qgpm%5Fsep%5Fmw%5F9da41ba9-8cb4-4909-9926-d3ad722ab6f3)) returns the classification margins for Mdl using the predictor data in matrix X and the class labels in Y.

The classification margin is the difference between the classification score for the true class and the maximal classification score for the false classes.m is returned as a numeric vector with the same length asY.

example

Examples

collapse all

Compute the classification margin for the Fisher iris data.

Compute the classification margin for the Fisher iris data, trained on its first two columns of data, and view the last 10 entries:

load fisheriris X = meas(:,1:2); obj = fitcdiscr(X,species); M = margin(obj,X,species); M(end-10:end)

ans = 0.6551 0.4838 0.6551 -0.5127 0.5659 0.4611 0.4949 0.1024 0.2787 -0.1439 -0.4444

Compute the classification margin for the Fisher iris data, trained on its first two columns of data, and view the last 10 entries:

obj = fitcdiscr(meas,species); M = margin(obj,meas,species); M(end-10:end)

ans = 0.9983 1.0000 0.9991 0.9978 1.0000 1.0000 0.9999 0.9882 0.9937 1.0000 0.9649

Input Arguments

collapse all

Sample data, specified as a table. Each row of Tbl corresponds to one observation, and each column corresponds to one predictor variable. Categorical predictor variables are not supported. Optionally, Tbl can contain an additional columns for the response variable, which can be categorical.Tbl must contain all of the predictors used to train the model. Multicolumn variables and cell arrays other than cell arrays of character vectors are not allowed.

If you trained Mdl using sample data contained in a table, then the input data for margin must also be in a table.

Data Types: table

Predictor data, specified as a numeric matrix. Each row of X corresponds to one observation, and each column corresponds to one predictor variable. Categorical predictor variables are not supported. The variables in the columns ofX must be the same as the variables used to trainMdl. The number of rows in X must equal the number of rows in Y.

If you trained Mdl using sample data contained in a matrix, then the input data for margin must also be in a matrix.

Data Types: single | double

Response variable name, specified as the name of a variable in Tbl. IfTbl contains the response variable used to trainMdl, then you do not need to specifyResponseVarName.

You must specify ResponseVarName as a character vector or string scalar. For example, if the response variable Y is stored asTbl.Y, then specify it as "Y". Otherwise, the software treats all columns of Tbl, including Y, as predictors.

The response variable must be a categorical, character, or string array, a logical or numeric vector, or a cell array of character vectors. If the response variable is a character array, then each element must correspond to one row of the array.

Data Types: char | string

Class labels, specified as a categorical, character, or string array, a logical or numeric vector, or a cell array of character vectors. Y must have the same data type as the response data used to trainMdl. (The software treats string arrays as cell arrays of character vectors.)

The length of Y must equal the number of rows inTbl or X.

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

More About

collapse all

The classification margin is the difference between the classification score for the true class and maximal classification score for the false classes.

The classification margin is a column vector with the same number of rows as in the matrix X. A high value of margin indicates a more reliable prediction than a low value.

For discriminant analysis, the score of a classification is the posterior probability of the classification. For the definition of posterior probability in discriminant analysis, see Posterior Probability.

Extended Capabilities

expand all

Themargin function fully supports tall arrays. For more information, see Tall Arrays.

Version History

Introduced in R2011b