fitcecoc
statistics: Mdl = fitcecoc (X, Y)
statistics: Mdl = fitcecoc (…, name, value)
Fit a multiclass model from binary learners.
Mdl = fitcecoc (X, Y) turns the multiclass
problem in X and Y into a set of two class problems, fits one
binary learner to each, and returns them as a ClassificationECOC
object. A coding matrix says which classes each learner calls +1, which
it calls -1, and which sit it out; a new observation is sent to every
learner and given the class whose row of that matrix its scores match most
closely.
ClassNames accepts, with at least two distinct values.
| Name | Value | |
|---|---|---|
'Learners' | The binary learner, either a name,
'svm' (default), 'tree', 'knn',
'naivebayes', 'discriminant', 'linear',
'kernel' or 'ensemble', a LogitBoost ensemble of 100
trees, or a template from templateSVM and its siblings,
templateEnsemble among them, which also carries the options that
learner is to be fitted with. | |
'Coding' | The coding design, either a name
designecoc accepts, 'onevsone' by default, or a coding
matrix given outright, which sets CodingName to 'custom'. | |
'BinaryLoss' | The loss the binary scores are read
with. The default follows the learner: 'exponential' for an
AdaBoostM1 or GentleBoost ensemble, 'binodeviance' for a
LogitBoost one, and otherwise 'hinge' for one scoring on
(-Inf,+Inf) and 'quadratic' for one scoring on [0,1],
as a bagged, random subspace or RUSBoost ensemble does. | |
'ClassNames' | The classes to fit, and the order
the rows of the coding matrix, Prior and Cost take them in.
By default they are sorted. | |
'Cost' | A KxK matrix of misclassification
costs. The default is 1 - eye (K). | |
'Prior' | 'empirical' (default),
'uniform', or a vector with one element per class. | |
'Weights' | A nonnegative numeric vector with one element per observation. The default is uniform. | |
'CategoricalPredictors' | The predictors whose values
are levels, as indices, a logical vector or 'all', passed as given
to every binary learner, which codes them its own way; a nearest neighbour
learner takes only 'all' and a discriminant learner none. | |
'PredictorNames' | A cellstr of predictor names. | |
'ResponseName' | The name of the response variable. | |
'ScoreTransform' | A transform applied to the
returned scores. The default is 'none'. |
Source Code: fitcecoc
A linear or kernel learner carries no training data of its own, so
fitcecoc returns a CompactClassificationECOC for those two
and a ClassificationECOC for the other five, which is what R2024a
does.
'FitPosterior' is refused rather than quietly ignored: it installs
a fitted score transform on each binary learner, which needs the posterior
fitting this package does not have yet.
An ensemble template may name any classification method of
fitcensemble; a regression template is refused, as in MATLAB.
A RUSBoost ensemble scores each class with the weighted sum of its trees’
class probabilities, which no binary loss can read: MATLAB sets the loss
to 'unknown' and then cannot predict. Here those scores, and the
binary scores predict returns, are divided by the total weight of
the trees, which gives the weighted mean of their class probabilities, and
are read with 'quadratic' as a bagged ensemble’s are. This follows
R’s ebmc and adabag packages and scikit-learn, whose
AdaBoostClassifier and imbalanced-learn’s RUSBoostClassifier
built on it scale a boosted ensemble’s weighted votes the same way.
A binary learner that cannot be fitted, such as an AdaBoostM2 ensemble, which
needs three classes, stops the fit with its own error, where MATLAB warns and
predicts the majority class. An AdaBoostM1 learner whose first tree
separates its two classes keeps that tree, as fitcensemble does;
MATLAB keeps no tree and never predicts those classes from it.
Each binary learner is fitted with the weight its observations carry, which
the prior and any 'Weights' decide. The SVM, KNN, naive Bayes and
discriminant learners of this package take no observation weights, so when
those weights are unequal they are given instead the prior their two sides
hold, the prior MATLAB’s learners report, and weights that vary within a
class, which no prior can express, are refused for them. MATLAB weighs
each observation of those learners as well.
See also: ClassificationECOC, CompactClassificationECOC, designecoc, templateSVM, templateTree
Source Code: fitcecoc