-
-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
e40258f
Add max error metric
whiletruelearn 6905ee4
Fix typo
whiletruelearn 0e92ee3
Fix some imports
whiletruelearn 06f14d8
Adding some test for max error
whiletruelearn ea9d3f0
Add scorer for max error
whiletruelearn 7b8222f
Add max_error_scorer to fix the failing test
whiletruelearn 237759a
correct typo in scorer name
whiletruelearn 9f0f6de
Changes based on review comments
whiletruelearn 495d6f0
Sample weight initialization needs to be tweaked to make the test pass
whiletruelearn 0ab3513
Update sample weight only for the max_error scorer
whiletruelearn bb56761
Change the sample weight slightly
whiletruelearn 7cfdb71
Remove support for sample weight
whiletruelearn ae86ca4
Changes based on code review
whiletruelearn d85f997
Fix the doctest
whiletruelearn 361675a
update what's new
whiletruelearn 5b82f09
Update the PR number also
whiletruelearn e296cdd
Update the user guide
whiletruelearn ff35504
update the documentation based on review comments
whiletruelearn cb50f23
Add reference and style fix for doc to have 80 char limit
whiletruelearn f156d59
Update review comments
whiletruelearn 3e0dfcf
Doc updates
whiletruelearn a088a76
Better structuring of sentence
whiletruelearn 90d69db
Missed to add the word metric
whiletruelearn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
|
||
|
||
__ALL__ = [ | ||
"max_error", | ||
"mean_absolute_error", | ||
"mean_squared_error", | ||
"mean_squared_log_error", | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. PEP257: put a one-line summary here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed. |
||
max_error metric calculates the maximum residual error. | ||
|
||
whiletruelearn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Read more in the :ref:`User Guide <max_error>`. | ||
|
||
Parameters | ||
---------- | ||
y_true : array-like of shape = (n_samples) | ||
Ground truth (correct) target values. | ||
|
||
y_pred : array-like of shape = (n_samples) | ||
Estimated target values. | ||
|
||
Returns | ||
------- | ||
max_error : float | ||
A positive floating point value (the best value is 0.0). | ||
|
||
Examples | ||
-------- | ||
>>> from sklearn.metrics import max_error | ||
>>> y_true = [3, 2, 7, 1] | ||
>>> y_pred = [4, 2, 7, 1] | ||
>>> max_error(y_true, y_pred) | ||
1 | ||
""" | ||
y_type, y_true, y_pred, _ = _check_reg_targets(y_true, y_pred, None) | ||
check_consistent_length(y_true, y_pred) | ||
if y_type == 'continuous-multioutput': | ||
raise ValueError("Multioutput not supported in max_error") | ||
return np.max(np.abs(y_true - y_pred)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 purposesample_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.
See #3450 and #6217
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.