Lably
Skip to content

Multiclass classification

Problem in machine learning and statistical classification

  • 11 min read
  • 4 chapters

Related on Lably

Through Machine learning, Decision tree and K-nearest neighbors algorithm

While many classification algorithms (e.g., decision trees, k-NN, neural networks and multinomial logistic regression) naturally permit the use of more than two classes, some are by nature binary algorithms (e.g., classical binary support vector machine) and require decomposition strategies such as one-vs-all, one-vs-one, or ECOC to solve multiclass problems.

Multiclass classification should not be confused with multi-label classification, where multiple labels are to be predicted for each instance (e.g., predicting that an image contains both an apple and an orange, in the previous example).

Better-than-random multiclass models

From the confusion matrix of a multiclass model, we can determine whether a model does better than chance. Let K≥3 be the number of classes, O a set of observations, y^:O→{1,...,K} a model of the target variable y:O→{1,...,K} and ni,j be the number of observations in the set {y=i}∩{y^=j}. We note ni.=∑jni,j, n.j=∑ini,j, n=∑jn.j=∑ini., λi=ni.n and μj=n.jn. It is assumed that the confusion matrix (ni,j)i,j contains at least one non-zero entry in each row, that is λi>0 for any i. Finally we call "normalized confusion matrix" the matrix of conditional probabilities (P(y^=j∣y=i))i,j=(ni,jni.)i,j.

Intuitive explanation

The lift is a way of measuring the deviation from independence of two events A and B :

Lift(A,B)=P(A∩B)P(A)P(B)=P(A∣B)P(A)=P(B∣A)P(B)

We have Lift(A,B)>1 if and only if events A and B occur simultaneously with a greater probability than if they were independent. In other words, if one of the two events occurs, the probability of observing the other event increases.

A first condition to satisfy is to have Lift(y=i,y^=i)≥1 for any i. And the quality of a model (better or worse than chance) does not change if we over- or undersample the dataset, that is if we multiply each row Ri of the confusion matrix by a constant ci. Thus the second condition is that the necessary and sufficient conditions for doing better than chance need only depend on the normalized confusion matrix.

The condition on lifts can be reformulated with One versus Rest binary models : for any i, we define the binary target variable yi which is the indicator of event {y=i}, and the binary model y^i of yi which is the indicator of event {y^=i}. Each of the y^i models is a "One versus Rest" model. Lift(y=i,y^=i) only depends on the events {y=i} and {y^=i}, so merging or not merging the other classes doesn't change its value. We therefore have Lift(y=i,y^=i)=Lift(yi=1,y^i=1) and the first condition is that all binary One versus Rest models are better than chance.

Example

If K=2 and 2 is the class of interest , the normalized confusion matrix is (specificity1−specificity1−sensitivitysensitivity) and we have Lift(y=1,y^=1)−1=P(y=y^=1)λ1μ1−1=n1,1nn1.n.1−1 =n1,1(n1,1+n1,2+n2,1+n2,2)−(n1,1+n1,2)(n1,1+n2,1)n1.n.1=n1,1n2,2−n1,2n2,1n1.n.1. Thus Lift(y=1,y^=1)≥1⟺n1,1n2,2−n1,2n2,1≥0. Similarly, by swapping the roles of 1 and 2, we find that Lift(y=2,y^=2)≥1⟺n1,1n2,2−n1,2n2,1≥0. Dividing by n1.n2. we find that the necessary and sufficient condition on the normalized confusion matrix is sensitivityspecificity−(1−sensitivity)(1−specificity)≥0⟺sensitivity+specificity−1≥0⟺J≥0. This brings us back to the classical binary condition: Youden's J must be positive (or zero for random models).

Random models

A random model is a model that is independent of the target variable. This property is easily reformulated with the confusion matrix.

Proposition—The model y^ of y is random if and only if the confusion matrix is of rank 1.

Proof

y^ is a random model of y if and only if we have P({y=i}∩{y^=j})=P(y=i)P(y^=j) for any i and j, which is equivalent to ni,jn=ni.n.j for any i and j. All the columns of the confusion matrix are then proportional to the non-zero vector (ni.)i , which implies that the confusion matrix is of rank 1.

Conversely, if this matrix is of rank 1, the non-zero columns of the matrix are proportional to each other, and therefore proportional to their sum (ni.)i. So there exists a family of numbers (βj)j such that ni,j=ni.βj for any i and j. Summing this equations over i gives n.j=βjn, hence ni,jn=ni.n.j for any i and j.

This proposition shows that the model y^ of y is uninformative if and only if there are two families of numbers (αi)i and (βj)j such that P({y=i}∩{y^=j})=αiβj for any i and j.

Multiclass likelihood ratios and diagnostic odds ratios

We define generalized likelihood ratios calculated from the normalized confusion matrix: for any i and j≠i, let LRi,j=P(y^=j∣y=j)P(y^=j∣y=i). When K=2, if 2 is the class of interest,, we find the classical likelihood ratios LR1,2=LR+ and LR2,1=1LR−. Multiclass diagnostic odds ratios can also be defined using the formula DORi,j=DORj,i=LRi,jLRj,i=ni,inj,jni,jnj,i=P(y^=j∣y=j)/P(y^=i∣y=j)P(y^=j∣y=i)/P(y^=i∣y=i)

Theorem—For any j,

P(y^=j∣y=j)−μj=∑iλi(P(y^=j∣y=j)−P(y^=j∣y=i))

Equivalently, if all ni,j are non-zero:

1Lift(y=j,y^=j)=∑iλiLRi,j

Proof

P(y^=j∣y=j)−P(y^=j)=P(y^=j∣y=j)−∑iλiP(y^=j∣y=i) =∑iλi(P(y^=j∣y=j)−P(y^=j∣y=i)). By dividing by P(y^=j∣y=j) and subtracting 1, we deduce the second formulation.

Corollary—If all probabilities P(y^=k∣y=l) are fixed, for any i and j we have

limλi→1(P(y^=j∣y=j)−μj)=P(y^=j∣y=j)−P(y^=j∣y=i)

Equivalently, if all ni,j are non-zero:

limλi→1Lift(y=j,y^=j)=LRi,j

We saw above that a better-than-chance model (or a random model) must verify Lift(y=i,y^=i)≥1 for any i and λi. According to the previous corollary, likelihood ratios are thus greater than or equal to 1. Conversely, if the likelihood ratios are greater than or equal to 1, the theorem shows that we have Lift(y=i,y^=i)≥1 for any i and λi.

Definition of better-than-chance multiclass models

A model y^ of y outperforms chance if the following conditions are met:

  • For any j, we have maxiP(y^=j∣y=i)=P(y^=j∣y=j).
  • There are i and j distinct such that P(y^=j∣y=i)<P(y^=j∣y=j).

If all the entries of the confusion matrix are non-zero, this means that all the likelihood ratios are greater than or equal to 1, and at least one of these inegalities is strict. A model that satisfies the first condition but not the second is random, since we then have P({y^=j}∩{y=i})=P(y=i)P(y^=j∣y=i)=P(y=i)P(y^=j∣y=j)=αiβj for any i and j.

We can rewrite the first condition in a more familiar way, noting x the observed value of y^, θ the value to be estimated of y and θ^(x) the set argmaxθP(x∣θ): for any x we have x∈θ^(x). We deduce that a model is better-than-random or random if and only if it is a maximum likelihood estimator of the target variable.

Applications

Multiclass balanced accuracy

The performance of a better-than-chance model can be estimated using multiclass versions of metrics such as balanced accuracy or Youden's J.

Definition—Balancedaccuracy=1K∑iP(y^=i∣y=i) J=1K−1(Kbalancedaccuracy−1)=1K−1∑iμi(Lift(y=i,y^=i)−1)

If balancedaccuracy=1, in other words J=1, the model is perfect. And for any random model, we have balancedaccuracy=1K (if, for example, we draw a uniform random number from the K labels, we have exactly one chance in K of predicting the correct value of the target variable).

On a balanced data set (λi=1K for any i), balanced accuracy is equal to the rate of well-classified observations. On any data set, if a model does better than chance, we have J≥0 and balancedaccuracy≥1K. But the converse is not true when K>2, as we can see from this example: the confusion matrix (030120003) is that of a bad model (=worse than chance) since LR2,1=0. However, 5 of the 9 observations are correctly classified. This also shows that poor model performance on one of the modalities is not compensated for by good performance on the other modalities.

ROC space

The set of normalized confusion matrices is called the ROC space, a subspace of [0,1]m2. If E denotes the subset of the ROC space made up of random models or models that do better than chance, one can show that the topological boundary of E is the set of elements of E for which at least one of the likelihood ratios is equal to 1. And random models are those models whose likelihood ratios are all equal to 1. When K=2, the boundary between models that do better than chance and bad models is equal to the set of random models (see article on the roc curve for more details), but it is strictly larger as soon as K>2. And if K=3, we can calculate the volume occupied by bad models in the ROC space: they occupy 90% of this space, whereas it's only 50% when K=2.

Sign in to keep reading

3 more chapters are free with a Lably account.

More in Computing and communication