Categories &

Functions List

Function Reference: designecoc

statistics: M = designecoc (K, name)
statistics: M = designecoc (…, 'NumTrials', n)

Coding design matrix for an error correcting output codes model.

M = designecoc (K, name) returns the coding design for K classes named by name. M is a KxL matrix of -1, 0 and +1 with one row per class and one column per binary learner: a learner is trained to tell the classes marked +1 in its column from those marked -1, and a class marked 0 takes no part in it.

K must be an integer of at least 2. name must be one of:

DesignColumnsDescription
'onevsone'K(K-1)/2One column per pair of classes, the earlier class +1 and the later -1, pairs taken in order.
'onevsall'KOne column per class, that class +1 and every other -1.
'binarycomplete'2^(K-1)-1Every way of splitting the classes into two non-empty groups, with the first class always +1.
'ternarycomplete'(3^K-2^(K+1)+1)/2Every way of splitting into two non-empty groups while leaving any classes out. It grows fast: 28501 columns at K = 10.
'ordinal'K-1Column j separates the first j classes from the rest, for classes that are ordered.
'denserandom'about 10log_2 KRandom -1 and +1, no class left out.
'sparserandom'about 15log_2 KRandom -1, 0 and +1, a class left out of a column with probability 0.5.

Source Code: designecoc

M = designecoc (…, 'NumTrials', n) draws n random designs and keeps the one whose rows are furthest apart, which is what makes a random design correct errors. The default is 10000. It is accepted but does nothing for the five designs that are not random.

K = 2 gives the single column [-1; 1] whatever the design, there being only one way to tell two classes apart.

Deviation from MATLAB

The two random designs cannot be reproduced from MATLAB and neither can their width. Measured on R2024a: five runs at K = 10 gave 'denserandom' 38, 38, 38, 40 and 40 columns and 'sparserandom' 57, 55, 55 and 54, so the number of columns varies between runs of MATLAB itself. The five other designs are exact.

See also: fitcecoc, ClassificationECOC

Source Code: designecoc