edge
Classification edge for discriminant analysis classifier
Syntax
Description
returns the classification Edge
e
= edge(Mdl
,Tbl
,ResponseVarName
)e
for the trained discriminant analysis classifier model
Mdl
using the predictor data in table Tbl
and
the class labels in Tbl.ResponseVarName
.
The classification edge is the weighted mean value of the classification Margin.
returns the classification edge e
= edge(___,Weights=weights
)e
using the weights in
weights
.
Note
If the predictor data X
contains any missing values, the
edge
function might return NaN. For more details, see
edge might return NaN for predictor data with missing values.
Examples
Classification Edge and Margin for Fisher Iris Data
Compute the classification edge and 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);
E = edge(obj,X,species)
E = 0.4980
M = margin(obj,X,species); M(end-10:end)
ans = 11×1
0.6551
0.4838
0.6551
-0.5127
0.5659
0.4611
0.4949
0.1024
0.2787
-0.1439
⋮
The classifier trained on all the data is better.
obj = fitcdiscr(meas,species); E = edge(obj,meas,species)
E = 0.9454
M = margin(obj,meas,species); M(end-10:end)
ans = 11×1
0.9983
1.0000
0.9991
0.9978
1.0000
1.0000
0.9999
0.9882
0.9937
1.0000
⋮
Input Arguments
Mdl
— Trained discriminant analysis classifier
ClassificationDiscriminant
model object | CompactClassificationDiscriminant
model object
Trained discriminant analysis classifier, specified as a ClassificationDiscriminant
model object trained with fitcdiscr
, or a CompactClassificationDiscriminant
model
object created with compact
.
X
— Predictor data
numeric matrix
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 of
X
must be the same as the variables used to train
Mdl
. 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 edge
must also be in a matrix.
Data Types: single
| double
Tbl
— Sample data
table
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 edge
must also be in a table.
Data Types: table
ResponseVarName
— Response variable name
name of a variable in Tbl
Response variable name, specified as the name of a variable in Tbl
. If
Tbl
contains the response
variable used to train Mdl
,
then you do not need to specify
ResponseVarName
.
If you specify ResponseVarName
, you must specify it as a character vector
or string scalar. For example, if the response
variable Y
is stored as
Tbl.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
Y
— Class labels
categorical array | character array | string array | logical vector | numeric vector | cell array of character vectors
Class labels, specified as a categorical, character, or string array, a logical or numeric
vector, or a cell array of character vectors. Y
must be
of the same type as the classification used to train Mdl
.
(The software treats string
arrays as cell arrays of character vectors.)
The length of Y
must equal the number of rows in
Tbl
or X
.
Data Types: categorical
| char
| string
| logical
| single
| double
| cell
More About
Edge
The edge is the weighted mean value of the classification margin. The weights are class prior probabilities. If you supply additional weights, those weights are normalized to sum to the prior probabilities in the respective classes, and are then used to compute the weighted average.
Margin
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.
Score (discriminant analysis)
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
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
Version History
Introduced in R2011bR2022a: edge
might return NaN for predictor data with missing values
The edge
function no longer omits an observation with a
NaN score when computing the weighted mean of the classification margins. Therefore,
edge
might now return NaN when the predictor data
X
contains any missing values. In most cases, if the test set
observations do not contain missing predictors, the edge
function does not return NaN.
This change improves the automatic selection of a classification model when you use
fitcauto
.
Before this change, the software might select a model (expected to best classify new data)
with few non-NaN predictors.
If edge
in your code returns NaN, you can update your code
to avoid this result. Remove or replace the missing values by using rmmissing
or fillmissing
, respectively.
The following table shows the classification models for which the
edge
object function might return NaN. For more details, see
the Compatibility Considerations for each edge
function.
Model Type | Full or Compact Model Object | edge Object Function |
---|---|---|
Discriminant analysis classification model | ClassificationDiscriminant , CompactClassificationDiscriminant | edge |
Ensemble of learners for classification | ClassificationEnsemble , CompactClassificationEnsemble | edge |
Gaussian kernel classification model | ClassificationKernel | edge |
k-nearest neighbor classification model | ClassificationKNN | edge |
Linear classification model | ClassificationLinear | edge |
Neural network classification model | ClassificationNeuralNetwork , CompactClassificationNeuralNetwork | edge |
Support vector machine (SVM) classification model | edge |
See Also
Classes
Functions
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
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: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)