[MRG] faster, flatter precision_recall_fscore_support#2278
[MRG] faster, flatter precision_recall_fscore_support#2278ogrisel merged 8 commits intoscikit-learn:masterfrom
Conversation
|
Thanks @jnothman :-) Can you rebase on top of master? |
|
Sure -- the only conflict was the module's lengthy author list and imports. |
sklearn/metrics/metrics.py
Outdated
There was a problem hiding this comment.
Apparently, I let example-based instead of sample-based
There was a problem hiding this comment.
indeed. and I've missed it multiple times since!
|
Why have you removed the improvements of the mcc metric? |
|
Awesome refarctoring !!! |
Uhh... apparently a git-user fail. I think I rebased an old version of my branch. I might need to go searching for the right one. |
|
Thank you Travis for recording my previous branch head (b81a68f6296753c52f45b0ebbc0b8b466f84b871). |
|
re-rebased with your comments (except for moving the elif case) addressed. |
There was a problem hiding this comment.
The ignore_warnings decorator I introduce in #2334 would be better applied here, but I don't really have the time to fix up either PR atm.
|
Travis is not happy :-/ |
Then nor am I. It's actually a worry, because the error is in |
|
I am able to reproduce the error on my laptop. Strange, the use of seterrstate and geterrstate seems to have some side effects. |
|
Is that correct behaviour, or is the warning meant to happen on nan? |
|
Given this test I would say that we should raise a warning. So in the end, this should be, |
sklearn/metrics/metrics.py
Outdated
There was a problem hiding this comment.
You might want to indicate here that 'modifier' and 'average' are strings used for the warning. It is hard to guess from the name of the function and the argument names.
|
Apparently Travis doesn't like that suggestion either. The plot thickens. I'm open to suggestions. |
|
Strange, I though this would work. Should we ignore the warning and launch our own when the denominator is 0? |
|
I think you misinterpreted the test code: it means the test should fail if On Thu, Aug 1, 2013 at 10:33 PM, Arnaud Joly notifications@github.comwrote:
|
|
LGTM 👍, thanks a lot this is a lot better than the previous version! |
|
A last review? |
There was a problem hiding this comment.
Could you please add an inline comment to explain when the invalid errstate could be triggered and why it's safe to ignore it in the specific case of matthews_corrcoef computation?
There was a problem hiding this comment.
I don't know anything about it. This simply reverts the code to an implementation before it was adapted to handle string input, with a LabelEncoder thrown on top.
|
Apart from my warning class comment, the code looks simple enough and I trust the test suite and your bench results. +1 for merging. |
There was a problem hiding this comment.
Actually I don't understand how this format string could possibly work. Could you please add a test that catches this specific warning and check the actual message content?
There was a problem hiding this comment.
Okay. The tricky bit is the {{}} which format expands to {} to be substituted with "due to" or "in labels with" or "in samples with".
You're telling me I shouldn't look for jobs in NLG? :p
There was a problem hiding this comment.
Alright I got it after writing the comment and re-reading the end of the function. Still an explicit test that checks the message would be very welcomed.
There was a problem hiding this comment.
This comment about adding a check for the message content has not been addressed, or has it?
There was a problem hiding this comment.
Sorry it has been in 0ea0aedef72306260097abff6ed786dedae1794b. I wonder how I missed it...
|
The travis failure looks real: |
|
I cannot reproduce the test failure on my box either. The |
There was a problem hiding this comment.
Could we use numpy or python warning instead?
There was a problem hiding this comment.
Which one? It's better to have specific warning classes to allow the user to silence specific warning categories.
There was a problem hiding this comment.
Depending of the situation, we can use either divide by zero warning or invalid.
There was a problem hiding this comment.
Certainly, we could inherit from one of those.
There was a problem hiding this comment.
+1 for keeping a specific class, optionally inheriting from the one that makes most sense.
There was a problem hiding this comment.
I'm happy to consider inheriting from RuntimeWarning rather than UserWarning, since it is intended for "dubious runtime behaviour". Yet we use UserWarnings everywhere else in sklearn, despite the docstring "Base class for warnings generated by user code."
The numpy warnings aren't relevant, IMO. This isn't some arbitrary numerical issue, it's about implementation details of metrics where the input isn't within the metric's natural domain, but the function must return some value, and there are multiple options as to what value.
So, what do you suggest?
There was a problem hiding this comment.
I don't have any strong opinion. I want to avoid adding a new warning class if one of the standard library does the job.
I'm happy to consider inheriting from RuntimeWarning rather than UserWarning, since it is intended for "dubious runtime behaviour". Yet we use UserWarnings everywhere else in sklearn, despite the docstring "Base class for warnings generated by user code."
RuntimeWarning looks appropriate (Base class for warnings about dubious runtime behavior.).
There was a problem hiding this comment.
I want to avoid adding a new warning class if one of the standard library does the job.
In terms of warnings, I understand "does the job" as: where a user might want to silence a particular warning or turn it into an exception, it should be easy, unambiguous and version-invariant.
This means it should have a specific class to distinguish it from other warnings in the module if that seems appropriate. @ogrisel suggested it might be in this case. Backwards-compatibility would have me extend from UserWarning.
There was a problem hiding this comment.
Alright. I think we can keep UserWarning for now. If we ever devise an official inheritance tree for sklearn warnings we might want to revise that choice later.
|
The travis failure must be yet another unexpected warning interaction. I'll try to sleuth it out. |
* Rewritten for efficiency and neatness. Note the handling of multilabel-sequences format by binarizing is in response to benchmarks. * Also fixed some warning handling in tests
Maybe duplicated warnings inside the same warning.catch block are collected only once under certain circumstances? |
|
No, that's not the issue. The issue is that the register of past warnings for its 'once' operation to work is buggy, though I've lost the Python bug tracker id for now. I've traced the present problem down to the |
|
found that and another one in the |
|
Great, well done @jnothman! |
|
Once @arjoly's comment is addressed, +1 for merging. |
|
LGTM +1 ! |
[MRG] faster, flatter precision_recall_fscore_support
|
Merged! Thanks @jnothman |
|
Thanks @jnothman !!! 👍 🍻 |
LabelEncoderto handle non-int labels instead.