Compute Classification Margin and Edge
Compute the classification margin and edge 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); tree = fitctree(X,species); E = edge(tree,X,species) E = 0.6299 M = margin(tree,X,species); M(end-10:end)
ans = 0.1111 0.1111 0.1111 -0.2857 0.6364 0.6364 0.1111 0.7500 1.0000 0.6364 0.2000
The classification tree trained on all the data is better.
tree = fitctree(meas,species); E = edge(tree,meas,species) E = 0.9384 M = margin(tree,meas,species); M(end-10:end)
ans = 0.9565 0.9565 0.9565 0.9565 0.9565 0.9565 0.9565 0.9565 0.9565 0.9565 0.9565
Specify optional pairs of arguments as
the argument name and
Value is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name in quotes.
Weights — Observation weights
ones(size(X,1),1) (default) | name of a variable in
TBL | numeric vector
Observation weights, specified as a numeric vector or the name of a variable in
If you specify
Weights as a numeric vector, then the size of
Weights must be equal to the number of rows in
If you specify
Weights as the name of a variable in
TBL, you must do so as a character vector or string scalar. For
example, if the weights are stored as
TBL.W, then specify it as
'W'. Otherwise, the software treats all columns of
If you supply weights,
edge computes the weighted classification edge. The
software weights the observations in each row of
TBL with the corresponding weight in
E — Classification edge
Classification edge, returned as a scalar representing the weighted average value of the margin.
The classification margin is the difference between the
classification score for the true class and maximal classification
score for the false classes. Margin is a column vector with the same number of rows as the
For trees, the score of a classification of a leaf node is the posterior probability of the classification at that node. The posterior probability of the classification at a node is the number of training sequences that lead to that node with the classification, divided by the number of training sequences that lead to that node.
For an example, see Posterior Probability Definition for Classification Tree.
The edge is the weighted mean value of the classification margin.
The weights are the class probabilities in
.Prior. If you supply weights in the
weights name-value pair, those weights are normalized to sum to the
prior probabilities in the respective classes, and are then used to compute the weighted
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
Usage notes and limitations:
edgefunction does not support decision tree models trained with surrogate splits.
For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).
Introduced in R2011a