-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
[MRG+2] Add max_error to the existing set of metrics for regression #12232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some test
Add [WIP] to the PR name |
Is this metric widely used? Do you have some more references about the metric? Personally I'm not persuaded to add it. |
@qinhanmin2014 I have updated scorer and It is cited as as a metric here |
I've read that in your issue but I don't think it's persuasive. Some papers/books/a wiki entry might be better from my side, or you can wait to see if other core devs will support you. We already have many metrics and I'm personally a bit selective for new metrics. |
@qinhanmin2014 Thanks for the review. I am closing this PR. Wanted to get your thoughts on this. I see bunch of other metrics related to regression.
Is there any historical reason why these metrics are not considered. Or would it be nice to have them implemented?. I see that |
I sincerely, heard about this very little. But, I will prefer to have more and not less. |
@eamanu I'm not opposed to more metrics, my point here is that we should ensure that the metrics we included are well-defined and widely accepted, but none of you have provided sufficient evidence to show that this metric is widely accepted. |
@whiletruelearn Thanks for the PR. If you want more feedback from others, feel free to reopen it :)
MAPE is likely to be included in 0.21 (see #10711) |
I get why this might be useful as a diagnostic measure. I think its meaning
is unambiguous for single output regression. I wouldn't object to providing
it with appropriate motivation in the user guide.
|
@jnothman can i reopen this PR and work on this ? |
This is also what I want to know about the metric. |
@jnothman I feel the same way. It is a simple diagnostic measure that will tell how good a fit the model is. It is straightforward to understand for everyone. @qinhanmin2014 Sharing a bunch of links where people have discussed about this metric. Having dived a little deeper, i feel this metric can be useful. [1] https://stats.stackexchange.com/questions/197642/linear-fit-how-to-minimize-maximum-error-rather-than-average-error Please let me know if i need something else to be changed |
In my previous comments, I'm not arguing that this metric is not well-defined. I'm worrying about whether it's widely accepted.
Thanks for these materials, but they are about a regression method which minimize maximum error, right? (apologies if I missed something in the 100+ page reference). I'd rather see something defining such a metric, though these seems enough to keep me +0 instead of -1 for it. |
@@ -573,3 +574,37 @@ def r2_score(y_true, y_pred, sample_weight=None, | |||
avg_weights = multioutput | |||
|
|||
return np.average(output_scores, weights=avg_weights) | |||
|
|||
|
|||
def max_error(y_true, y_pred): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can support sample_weight here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought about this for some time . Does it make sense to add? I see that median_absolute_error
also doesn't accept sample weight. We are calculating the max residual error right, i couldn't fully understand the purpose sample_weight
would provide here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I have made the change. Can you please review.
sklearn/metrics/__init__.py
Outdated
@@ -60,6 +60,7 @@ | |||
from .regression import mean_squared_log_error | |||
from .regression import median_absolute_error | |||
from .regression import r2_score | |||
from .regression import max_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alphabet order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
sklearn/metrics/regression.py
Outdated
1.0 | ||
""" | ||
y_type, y_true, y_pred, _ = _check_reg_targets(y_true, y_pred, | ||
'uniform_average') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems awkward. If we decide to include the metric, we might add a default value to multioutput
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed it to None
. Is that the right approach?
sklearn/metrics/regression.py
Outdated
'uniform_average') | ||
if y_type == 'continuous-multioutput': | ||
raise ValueError("Multioutput not supported in max_error") | ||
max_error = np.around(np.max(np.abs(y_true - y_pred)), decimals=3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @qinhanmin2014. Or why not create a parameter to set the decimal number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed.
@qinhanmin2014 sorry for not stating clearly earlier. section 2.3 speaks about this metric. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tbh I don't know much about regression evaluation either, but this intuitively seems reasonable to me. The question of whether it's inappropriate to maintain this along with all the others is hard to decide, when someone may indeed question sample_weight support, or multi-output regression...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll follow Joel, @whiletruelearn please add something to the user guide.
Please add an entry to the change log at |
At least it's straightforward and easy to maintain :) |
When you add the entry to the change log (@qinhanmin2014 comment), it will ready for me. |
Thanks @jnothman @qinhanmin2014 @eamanu . I have updated the change log as well. |
please add something to the user guide. |
@qinhanmin2014 do you mean over |
@qinhanmin2014 I have updated the user guide. Can you please let me know if this if fine ? |
Thanks @jnothman . I have updated the docs based on your suggestion. |
doc/modules/model_evaluation.rst
Outdated
Max error | ||
------------------- | ||
|
||
The :func:`max_error` function computes the maximum `residual error <https://en.wikipedia.org/wiki/Errors_and_residuals`_, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please generally keep under 80 chars per line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
@qinhanmin2014 @jnothman I have made the changes as per review comments. Can you please let me know if there are any other changes to make? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some formatting issues. It would be better if you check your PR carefully again :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @whiletruelearn
doc/whats_new/v0.21.rst
Outdated
:mod:`sklearn.metrics` | ||
...................... | ||
|
||
- |Feature| A new regression metric: :class:`metrics.max_error`: a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. Also changed it from :class:
to :func:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @whiletruelearn
Reference Issues/PRs
Fixes #12231
What does this implement/fix? Explain your changes.
Added a new metric for regression which is
max_error
. It is the worst case error between the predicted value and the true value.Any other comments?