Multi-label classification

Multi-label classification problem is a task to predict labels given two or more categories.

Each sample ii has lil_i labels, where LL is a set of unique labels in the dataset, and 0liL0 \leq l_i \leq |L|. This page focuses on evaluation of such multi-label classification problems.

Example

This page introduces toy example dataset for explanation.

Data

The following table shows examples of multi-label classification's prediction.

Suppose that animal names represent tags of blog posts and the given task is to predict tags for blog posts. The left column shows the ground truth labels and the right column shows predicted labels by a multi-label classifier.

truth labels predicted labels
cat, bird cat, dog
cat, dog cat, bird
cat (no truth label)
bird bird
bird, cat bird, cat
cat, dog cat, dog, bird
dog, bird dog

Evaluation metrics for multi-label classification

Hivemall provides micro F1-score and micro F-measure.

Define LL is the set of the tag of blog posts, and lil_i is a tag set of ii-th document. In the same manner, pip_i is a predicted tag set of ii-th document.

Micro F1-score

F1-score is the harmonic mean of recall and precision.

The value is computed by the following equation:

F1=2ilipi2ilipi+ilipi+ipili \mathrm{F}_1 = 2 \frac {\sum_i |l_i \cap p_i |} { 2* \sum_i |l_i \cap p_i | + \sum_i |l_i - p_i| + \sum_i |p_i - l_i| }

Caution

Hivemall also provides f1score function, but it is old function to obtain F1-score. The value of f1score is based on set operation. So, we recommend to use fmeasure function to get F1-score based on this article.

The following query shows the example to obtain F1-score.

WITH data as (
  select array("cat", "bird") as actual, array("cat", "dog")         as predicted
union all
  select array("cat", "dog")  as actual, array("cat", "bird")        as predicted
union all
  select array("cat")         as actual, array()                     as predicted
union all
  select array("bird")        as actual, array("bird")               as predicted
union all
  select array("bird", "cat") as actual, array("bird", "cat")        as predicted
union all
  select array("cat", "dog")  as actual, array("cat", "dog", "bird") as predicted
union all
  select array("dog", "bird") as actual, array("dog")                as predicted
)
select
  fmeasure(actual, predicted)
from data
;

0.6956521739130435

Micro F-measure

F-measure is generalized F1-score and the weighted harmonic mean of recall and precision.

The value is computed by the following equation: Fβ=(1+β2)ilipiβ2(ilipi+ilipi)+ilipi+ipili \mathrm{F}_{\beta} = (1+\beta^2) \frac {\sum_i |l_i \cap p_i |} { \beta^2 (\sum_i |l_i \cap p_i | + \sum_i |l_i - p_i|) + \sum_i |l_i \cap p_i | + \sum_i |p_i - l_i|}

β\beta is the parameter to determine the weight of precision. So, F1-score is the special case of F-measure given β=1\beta=1.

If β\beta is larger positive value than 1.0, F-measure reaches micro recall. On the other hand, if β\beta is smaller positive value than 1.0, F-measure reaches micro precision.

If β\beta is omitted, hivemall calculates F-measure with β=1\beta=1 (: equivalent to F1-score).

The following query shows the example to obtain F-measure with β=2\beta=2.

WITH data as (
  select array("cat", "bird") as actual, array("cat", "dog")         as predicted
union all
  select array("cat", "dog")  as actual, array("cat", "bird")        as predicted
union all
  select array("cat")         as actual, array()                     as predicted
union all
  select array("bird")        as actual, array("bird")               as predicted
union all
  select array("bird", "cat") as actual, array("bird", "cat")        as predicted
union all
  select array("cat", "dog")  as actual, array("cat", "dog", "bird") as predicted
union all
  select array("dog", "bird") as actual, array("dog")                as predicted
)
select
  fmeasure(actual, predicted, '-beta 2.')
from data
;

0.6779661016949152

results matching ""

    No results matching ""