[GitHub] incubator-hivemall pull request #107: [WIP][HIVEMALL-132] Generalize f1score...

2017-08-06 Thread nzw0301
Github user nzw0301 commented on a diff in the pull request:

https://github.com/apache/incubator-hivemall/pull/107#discussion_r131559560
  
--- Diff: docs/gitbook/eval/multilabel_classification_measures.md ---
@@ -0,0 +1,148 @@
+
+
+
+
+# Multi-label classification
+
+
+Multi-label classification problem is predicting the labels given 
categorized dataset.
+Each sample $$i$$ has $$l_i$$ labels ($$0 \leq  l_i \leq |L| $$  )
+, where $$L$$ is the number of unique labels in the geven dataset.
+
+This page focuses on evaluation of the results from such Multi-label 
classification problems.
+
+# Examples
+
+For the metrics explanation, this page introduces toy example data and two 
metrics.
+
+## Data
+
+The following table shows the sample of Multi-label classification's 
prediction.
+Animal names represent the tags of blog post.
+Left column includes supervised labels,
+Right column includes are predicted labels by a Multi-label classifier.
+
+| truth labels| predicted labels |
+|:---:|:---:|
+|cat, dog | cat, bird |
+| cat, bird | cat, dog |
+| | cat |
+| bird | bird |
+| bird, cat | bird, cat |
+| cat, dog, bird | cat, dog |
+| dog | dog, bird|
+
+
+# Evaluation metrics for multi-label classification
+
+Hivemall provises micro F1-score and micro F-measure.
+
+Given $$N$$ blog posts, we uses 
+
+Define $$L$$ is the set of the tag of blog posts, and 
+$$l_i$$ is a tag set of $$i$$th document.
+In the same manner,
+$$p_i$$ is a predicted tag set of $$i$$th document.
+
+
+
+## Micro F1-score
+
+
+F1-score is the harmonic mean of recall and precision.
+
+The value is computed by the following equation:
+
+$$
+\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 | }
+$$
+
+The Following query shows the example to obtain F1-score.
+
+```sql
+WITH data as (
+  select array("cat", "dog") as actual, array("cat", "bird") as 
predicted
+union all
+  select array("cat", "bird")as actual, array("cat", "dog")  as 
predicted
+union all
+  select array() as actual, array("cat") 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", "bird") as actual, array("cat", "dog")  as 
predicted
+union all
+  select array("dog")as actual, array("dog", "bird") as 
predicted
+)
+select
+  f1score(actual, predicted)
--- End diff --

Thank you for your review.
OK, I will update arguments.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-hivemall pull request #107: [WIP][HIVEMALL-132] Generalize f1score...

2017-08-06 Thread myui
Github user myui commented on a diff in the pull request:

https://github.com/apache/incubator-hivemall/pull/107#discussion_r131559068
  
--- Diff: docs/gitbook/eval/multilabel_classification_measures.md ---
@@ -0,0 +1,148 @@
+
+
+
+
+# Multi-label classification
+
+
+Multi-label classification problem is predicting the labels given 
categorized dataset.
+Each sample $$i$$ has $$l_i$$ labels ($$0 \leq  l_i \leq |L| $$  )
+, where $$L$$ is the number of unique labels in the geven dataset.
+
+This page focuses on evaluation of the results from such Multi-label 
classification problems.
+
+# Examples
+
+For the metrics explanation, this page introduces toy example data and two 
metrics.
+
+## Data
+
+The following table shows the sample of Multi-label classification's 
prediction.
+Animal names represent the tags of blog post.
+Left column includes supervised labels,
+Right column includes are predicted labels by a Multi-label classifier.
+
+| truth labels| predicted labels |
+|:---:|:---:|
+|cat, dog | cat, bird |
+| cat, bird | cat, dog |
+| | cat |
+| bird | bird |
+| bird, cat | bird, cat |
+| cat, dog, bird | cat, dog |
+| dog | dog, bird|
+
+
+# Evaluation metrics for multi-label classification
+
+Hivemall provises micro F1-score and micro F-measure.
+
+Given $$N$$ blog posts, we uses 
+
+Define $$L$$ is the set of the tag of blog posts, and 
+$$l_i$$ is a tag set of $$i$$th document.
+In the same manner,
+$$p_i$$ is a predicted tag set of $$i$$th document.
+
+
+
+## Micro F1-score
+
+
+F1-score is the harmonic mean of recall and precision.
+
+The value is computed by the following equation:
+
+$$
+\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 | }
+$$
+
+The Following query shows the example to obtain F1-score.
+
+```sql
+WITH data as (
+  select array("cat", "dog") as actual, array("cat", "bird") as 
predicted
+union all
+  select array("cat", "bird")as actual, array("cat", "dog")  as 
predicted
+union all
+  select array() as actual, array("cat") 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", "bird") as actual, array("cat", "dog")  as 
predicted
+union all
+  select array("dog")as actual, array("dog", "bird") as 
predicted
+)
+select
+  f1score(actual, predicted)
+from data
+;
+
+--- 0.6956521739130435;
+```
+
+
+## Micro F-measure
+
+F-measure is generalized F1-score and the weighted harmonic mean of recall 
and precision.
+
+$$\beta$$ is the parameter to determine the weight of precision.
+So, F1-score is the special case of F-measure given $$\beta=1$$.
+
+If $$\beta$$ is larger positive value than `1.0`, F-measure reaches to 
micro recall.
+On the other hand,
+if $$\beta$$ is smaller positive value than `1.0`, F-measure reaches to 
micro precision.
+
+The following query shows the example to obtain F-measure with $$\beta=2$$.
+
+$$
+\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 |p_i - l_i |) + \sum_i |l_i 
\cap p_i | + \sum_i |l_i - p_i |}
+$$
+
+
+```sql
+WITH data as (
+  select array("cat", "dog") as actual, array("cat", "bird") as 
predicted
+union all
+  select array("cat", "bird")as actual, array("cat", "dog")  as 
predicted
+union all
+  select array() as actual, array("cat") 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", "bird") as actual, array("cat", "dog")  as 
predicted
+union all
+  select array("dog")as actual, array("dog", "bird") as 
predicted
+)
+select
+  fmeasure(actual, predicted, 2)
--- End diff --

`fmeasure(actual, predicted, '-beta 2.0 -average macro')`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] incubator-hivemall pull request #107: [WIP][HIVEMALL-132] Generalize f1score...

2017-08-06 Thread myui
Github user myui commented on a diff in the pull request:

https://github.com/apache/incubator-hivemall/pull/107#discussion_r131559009
  
--- Diff: docs/gitbook/eval/multilabel_classification_measures.md ---
@@ -0,0 +1,148 @@
+
+
+
+
+# Multi-label classification
+
+
+Multi-label classification problem is predicting the labels given 
categorized dataset.
+Each sample $$i$$ has $$l_i$$ labels ($$0 \leq  l_i \leq |L| $$  )
+, where $$L$$ is the number of unique labels in the geven dataset.
+
+This page focuses on evaluation of the results from such Multi-label 
classification problems.
+
+# Examples
+
+For the metrics explanation, this page introduces toy example data and two 
metrics.
+
+## Data
+
+The following table shows the sample of Multi-label classification's 
prediction.
+Animal names represent the tags of blog post.
+Left column includes supervised labels,
+Right column includes are predicted labels by a Multi-label classifier.
+
+| truth labels| predicted labels |
+|:---:|:---:|
+|cat, dog | cat, bird |
+| cat, bird | cat, dog |
+| | cat |
+| bird | bird |
+| bird, cat | bird, cat |
+| cat, dog, bird | cat, dog |
+| dog | dog, bird|
+
+
+# Evaluation metrics for multi-label classification
+
+Hivemall provises micro F1-score and micro F-measure.
+
+Given $$N$$ blog posts, we uses 
+
+Define $$L$$ is the set of the tag of blog posts, and 
+$$l_i$$ is a tag set of $$i$$th document.
+In the same manner,
+$$p_i$$ is a predicted tag set of $$i$$th document.
+
+
+
+## Micro F1-score
+
+
+F1-score is the harmonic mean of recall and precision.
+
+The value is computed by the following equation:
+
+$$
+\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 | }
+$$
+
+The Following query shows the example to obtain F1-score.
+
+```sql
+WITH data as (
+  select array("cat", "dog") as actual, array("cat", "bird") as 
predicted
+union all
+  select array("cat", "bird")as actual, array("cat", "dog")  as 
predicted
+union all
+  select array() as actual, array("cat") 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", "bird") as actual, array("cat", "dog")  as 
predicted
+union all
+  select array("dog")as actual, array("dog", "bird") as 
predicted
+)
+select
+  f1score(actual, predicted)
--- End diff --

Could you change the optional third argument to take `const string options` 
?

`-beta 1.0 (default)`
`-average [micro (default), macro]`

http://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html#sklearn.metrics.f1_score

`f1score(actual, predicted)` equals to `fmeasure(actual, predicted, '-beta 
1.0 -average micro')` .

See `UDFWithOptions` and it's usage.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---