Hi,
Here is the code for balanced accuracy for two classes:
def balanced_accuracy(y_true, y_pred):
total_pos = 0
total_neg = 0
correct_pos = 0
correct_neg = 0
for k in range(len(y_true)):
if (y_true[k] < 0):
total_neg += 1;
if (y_pred[k] < 0):
correct_neg += 1
else:
total_pos += 1
if (y_pred[k] > 0):
correct_pos += 1
if (total_neg == 0 or total_pos == 0):
raise Exception("There is not any sample data for at least one of the
classes")
return (float(correct_pos)/total_pos+float(correct_neg)/total_neg)/2
However, it is also may be better to use confusion matrix implemented in
scikit. If you want I can also write the code for multi-class.
Cheers,
Hamed
On Tue, Jul 29, 2014 at 12:12 AM, Yogesh Karpate <[email protected]>
wrote:
> Dear Hamed,
> Can you share the code of "balanced accuracy" as you mentioned in last
> mail.
>
>
> On Tue, Jul 29, 2014 at 12:07 AM, Hamed Zamani <[email protected]>
> wrote:
>
>> Dear Mario,
>>
>> Yes of course. Sorry I forgot to mention GMeans. It is also one of the
>> measures which have been used frequently.
>>
>> -- Hamed
>>
>>
>>
>> On Tue, Jul 29, 2014 at 2:24 AM, Mario Michael Krell <[email protected]
>> > wrote:
>>
>>> Dear Hamed,
>>>
>>> I think it would be a good idea to also consider gmean when extending
>>> scikit. It is the geometric mean of TNR and TPR instead of the arithmetic
>>> mean used for the balanced accuracy.
>>>
>>> Greets
>>>
>>> Mario
>>>
>>> On 28.07.2014, at 19:00,
>>> [email protected] wrote:
>>>
>>> Dear Joel,
>>>
>>> Sorry for the delay. I was in a trip and I couldn't check my email.
>>>
>>> To the best of my knowledge and according to the kind responses in this
>>> email thread, we cannot claim that an specific measure is better than the
>>> others for imbalanced data. In other words, there are some evaluation
>>> measure suitable for imbalanced data and each of them has its own
>>> advantages. Hence, choosing the best evaluation measure totally depends
>>> on
>>> the application which you are working on.
>>>
>>> Anyway, "Matthew's Correlation Coefficient", "AUC of ROC", "F-measure",
>>> "Balanced Accuracy", and generally "Weighted Accuracy" have been used
>>> frequently in the literature. Among these measures, only "balanced
>>> accuracy" is not developed in scikit-learn and I think it is worthwhile
>>> to
>>> add it to this library. I have developed it before and if you want I can
>>> add it to the project or send it to you.
>>>
>>> Kind Regards,
>>> Hamed
>>>
>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Infragistics Professional
>>> Build stunning WinForms apps today!
>>> Reboot your WinForms applications with our WinForms controls.
>>> Build a bridge from your legacy apps to the future.
>>>
>>> http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
>>>
>>> _______________________________________________
>>> Scikit-learn-general mailing list
>>> [email protected]
>>> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>>>
>>>
>>
>>
>> ------------------------------------------------------------------------------
>> Infragistics Professional
>> Build stunning WinForms apps today!
>> Reboot your WinForms applications with our WinForms controls.
>> Build a bridge from your legacy apps to the future.
>>
>> http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
>> _______________________________________________
>> Scikit-learn-general mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>>
>>
>
>
> --
> Warm Regards
> Yogesh Karpate
>
>
> ------------------------------------------------------------------------------
> Infragistics Professional
> Build stunning WinForms apps today!
> Reboot your WinForms applications with our WinForms controls.
> Build a bridge from your legacy apps to the future.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
> _______________________________________________
> Scikit-learn-general mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/scikit-learn-general
>
>
------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls.
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
Scikit-learn-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/scikit-learn-general