Main Content


Classification margin


mar = margin(B,TBLnew,Ynew)
mar = margin(B,Xnew,Ynew)
mar = margin(B,TBLnew,Ynew,'param1',val1,'param2',val2,...)
mar = margin(B,Xnew,Ynew,'param1',val1,'param2',val2,...)


mar = margin(B,TBLnew,Ynew) computes the classification margins for the predictors contained in the table TBLnew given true response Ynew. You can omit Ynew if TBLnew contains the response variable. If you trained B using sample data contained in a table, then the input data for this method must also be in a table.

mar = margin(B,Xnew,Ynew) computes the classification margins for the predictors contained in the matrix Xnew given true response Ynew.

Ynew can be a numeric vector, character matrix, string array, cell array of character vectors, categorical vector or logical vector. mar is a numeric array of size Nobs-by-NTrees, where Nobs is the number of rows of TBLnew and Ynew, and NTrees is the number of trees in the ensemble B. For observation I and tree J, mar(I,J) is the difference between the score for the true class and the largest score for other classes. This method is available for classification ensembles only.

mar = margin(B,TBLnew,Ynew,'param1',val1,'param2',val2,...) or mar = margin(B,Xnew,Ynew,'param1',val1,'param2',val2,...) specifies optional parameter name-value pairs:

'Mode'How the method computes errors. If set to 'cumulative' (default), margin computes cumulative errors and mar is an Nobs-by-NTrees matrix, where the first column gives error from trees(1), second column gives error fromtrees(1:2) etc., up to trees(1:NTrees). If set to 'individual', mar is a Nobs-by-NTrees matrix, where each element is an error from each tree in the ensemble. If set to 'ensemble', mar a single column of length Nobs showing the cumulative margins for the entire ensemble.
'Trees'Vector of indices indicating what trees to include in this calculation. By default, this argument is set to 'all' and the method uses all trees. If 'Trees' is a numeric vector, the method returns a vector of length NTrees for 'cumulative' and 'individual' modes, where NTrees is the number of elements in the input vector, and a scalar for 'ensemble' mode. For example, in the 'cumulative' mode, the first element gives error from trees(1), the second element gives error from trees(1:2) etc.
'TreeWeights' Vector of tree weights. This vector must have the same length as the 'Trees' vector. The method uses these weights to combine output from the specified trees by taking a weighted average instead of the simple non-weighted majority vote. You cannot use this argument in the 'individual' mode.
'UseInstanceForTree'Logical matrix of size Nobs-by-NTrees indicating which trees should be used to make predictions for each observation. By default the method uses all trees for all observations.

See Also