Hi,

Your problem is a binary classification task. In that
case, the f1 score function returns the binary classification
f1 score.

In order to get multi class classification score, you have to set pos_label to 
None.
For example,

In [2]: gt = [0, 0, 1, 1, 0, 0, 1, 1, 0]

In [3]: from sklearn.metrics import f1_score

In [4]: pr = [0, 0, 1, 0, 0, 0, 1, 0, 0
   ...: ]

In [5]: f1_score(gt, pr, labels=[0, 1], average="micro")
Out[5]: 0.66666666666666663

In [6]: f1_score(gt, pr, labels=[0, 1], average="macro")
Out[6]: 0.66666666666666663

In [7]: f1_score(gt, pr, labels=[0, 1], average=None)
Out[7]: array([ 0.83333333,  0.66666667])

In [8]: f1_score(gt, pr, labels=[0, 1], average=None, pos_label=None)
Out[8]: array([ 0.83333333,  0.66666667])

In [9]: f1_score(gt, pr, labels=[0, 1], average="micro", pos_label=None)
Out[9]: 0.77777777777777779

In [10]: f1_score(gt, pr, labels=[0, 1], average="macro", pos_label=None)
Out[10]: 0.75

This is a known problem. Currently Joel proposed a solution
to this problem in https://github.com/scikit-learn/scikit-learn/pull/2610.

Best,
Arnaud


On 16 Dec 2013, at 15:42, Yuan Luo <[email protected]> wrote:

> Hi,
> I am having trouble using the macro and micro averaged f1_score as shown below
> 
> >>> gt = [0, 0, 1, 1, 0, 0, 1, 1, 0];
> >>> gt
> [0, 0, 1, 1, 0, 0, 1, 1, 0]
> >>> pr = [0, 0, 1, 0, 0, 0, 1, 0, 0];
> >>> from sklearn.metrics import f1_score
> >>> f1_score(gt, pr, average='macro')
> 0.66666666666666663
> >>> f1_score(gt, pr, average=None)
> array([ 0.83333333,  0.66666667])
> >>> f1_score(gt, pr, average='micro')
> 0.66666666666666663
> >>> 
> 
> The non-averaged version seems fine, but averaged versions are confusing.
> Do you have any clues? I am using scikit-learn 0.14 with python 3.3
> 
> Best,
> Yuan
> ------------------------------------------------------------------------------
> Rapidly troubleshoot problems before they affect your business. Most IT 
> organizations don't have a clear picture of how application performance 
> affects their revenue. With AppDynamics, you get 100% visibility into your 
> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk_______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

------------------------------------------------------------------------------
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general

Reply via email to