Skip to content
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

[MRG+2] median_absolute_error multioutput #14732

Merged

Conversation

agamemnonc
Copy link
Contributor

@agamemnonc agamemnonc commented Aug 22, 2019

Reference Issues/PRs

Closes #14728.

What does this implement/fix? Explain your changes.

Implements multioutput for median_absolute_error.

Any other comments?

Shall we also include support for sample_weight in this PR? See also #6217.

@agamemnonc
Copy link
Contributor Author

@agamemnonc agamemnonc commented Aug 23, 2019

Not sure why Azure pipeline tests fail

sklearn/metrics/regression.py Outdated Show resolved Hide resolved
sklearn/metrics/regression.py Outdated Show resolved Hide resolved
sklearn/metrics/regression.py Outdated Show resolved Hide resolved
@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Aug 23, 2019

Regarding the failure, you need to add median_absolute_error in MULTIOUTPUT_METRICS in metrics/tests/test_common.py. Otherwise, we check that an error should be raised.

@agamemnonc
Copy link
Contributor Author

@agamemnonc agamemnonc commented Aug 23, 2019

Thanks @glemaitre .

Any thoughts regarding sample_weight ? Should we implement this in this PR or a perhaps a different one?

@agamemnonc agamemnonc changed the title median_absolute_error multioutput [WIP] median_absolute_error multioutput Aug 23, 2019
@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Aug 23, 2019

I would say to implement it in another PR. I am also not sure how to apply some weight during the computation of the median such that it is meaningful.

You would need to sort y and take the 50% value of the cumulative sum of the weights or something like that.

@agamemnonc agamemnonc changed the title [WIP] median_absolute_error multioutput [MRG] median_absolute_error multioutput Aug 23, 2019
sklearn/metrics/regression.py Outdated Show resolved Hide resolved
sklearn/metrics/regression.py Outdated Show resolved Hide resolved
@glemaitre glemaitre changed the title [MRG] median_absolute_error multioutput [MRG+1] median_absolute_error multioutput Sep 9, 2019
@agamemnonc
Copy link
Contributor Author

@agamemnonc agamemnonc commented Oct 14, 2019

Conflicts with master resolved.

Any willing reviewers? :)

@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Oct 21, 2019

if y_type == 'continuous-multioutput':
raise ValueError("Multioutput not supported in median_absolute_error")
return np.median(np.abs(y_pred - y_true))
_, y_true, y_pred, _ = _check_reg_targets(y_true, y_pred, None)
Copy link
Member

@qinhanmin2014 qinhanmin2014 Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to pass multioutput
this should be y_type, y_true, y_pred, multioutput = _check_reg_targets(y_true, y_pred, multioutput)

Copy link
Contributor Author

@agamemnonc agamemnonc Oct 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted.

Fixed.

@agamemnonc agamemnonc changed the title [MRG+1] median_absolute_error multioutput [MRG+2] median_absolute_error multioutput Oct 21, 2019
if y_type == 'continuous-multioutput':
raise ValueError("Multioutput not supported in median_absolute_error")
return np.median(np.abs(y_pred - y_true))
_, y_true, y_pred, _ = _check_reg_targets(y_true, y_pred, multioutput)
Copy link
Member

@qinhanmin2014 qinhanmin2014 Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use y_type, y_true, y_pred, multioutput = _check_reg_targets(y_true, y_pred, multioutput) here. This will be more consistent. (Actually since we call check_array in _check_reg_targets, multioutput will sometimes be modified.)

Copy link
Contributor Author

@agamemnonc agamemnonc Oct 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks. Now fixed.

Copy link
Member

@qinhanmin2014 qinhanmin2014 left a comment

will merge when green.

@glemaitre glemaitre merged commit d026e32 into scikit-learn:master Oct 22, 2019
19 checks passed
@glemaitre
Copy link
Contributor

@glemaitre glemaitre commented Oct 22, 2019

Let's merge then.

Thanks @agamemnonc!!!

@agamemnonc agamemnonc deleted the median_absolute_error_multioutput branch Oct 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants