Multi-label classification
Multi-label classification problem is a task to predict labels given two or more categories.
Each sample has labels, where is a set of unique labels in the dataset, and . 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 is the set of the tag of blog posts, and is a tag set of -th document. In the same manner, is a predicted tag set of -th document.
Micro F1-score
F1-score is the harmonic mean of recall and precision.
The value is computed by the following equation:
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:
is the parameter to determine the weight of precision. So, F1-score is the special case of F-measure given .
If is larger positive value than 1.0
, F-measure reaches micro recall.
On the other hand,
if is smaller positive value than 1.0
, F-measure reaches micro precision.
If is omitted, hivemall calculates F-measure with (: equivalent to F1-score).
The following query shows the example to obtain F-measure with .
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