Skip to content

Common check for sample weight invariance with removed samples #17176

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 10 commits into from
Jun 3, 2020

Conversation

rth
Copy link
Member

@rth rth commented May 10, 2020

Same as #16507 but taking into account latest updates in check_estimator and handling of xfail estimators.

I initially tried to fix this quickly in #17175, but in the end decided to revert the inital commit to fix CI and do a less rushed solution in this PR.

@rth
Copy link
Member Author

rth commented May 10, 2020

cc @NicolasHug .

We need to first merge #16963 I think. Earlier version of this PR basically implemented a simpler version of that PR.

@NicolasHug
Copy link
Member

I guess we need to start with #17134 then :p

@rth
Copy link
Member Author

rth commented May 15, 2020

@NicolasHug This PR should be good now. The coverage failure doesn't look relevant.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @rth, a few nits but LGTM!

@@ -845,7 +846,7 @@ def check_sample_weights_shape(name, estimator_orig):


@ignore_warnings(category=FutureWarning)
def check_sample_weights_invariance(name, estimator_orig):
def check_sample_weights_invariance(name, estimator_orig, kind="ones"):
# check that the estimators yield same results for
# unit weights and no weights
if (has_fit_parameter(estimator_orig, "sample_weight") and
Copy link
Member

Choose a reason for hiding this comment

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

while we're at it we might as well return early here instead of having the entire function in a if block?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually moved this _yield_all_checks to only run check_sample_weight on estimators that support it. If find that showing a green status for a check when it doesn't apply is not great (and skipping it also produces too much noise).

@@ -861,25 +862,45 @@ def check_sample_weights_invariance(name, estimator_orig):
X = np.array([[1, 3], [1, 3], [1, 3], [1, 3],
[2, 1], [2, 1], [2, 1], [2, 1],
[3, 3], [3, 3], [3, 3], [3, 3],
[4, 1], [4, 1], [4, 1], [4, 1]], dtype=np.dtype('float'))
[4, 1], [4, 1], [4, 1], [4, 1]], dtype=np.float64)
Copy link
Member

Choose a reason for hiding this comment

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

for consistency these could be X1 and y1

rth and others added 3 commits May 15, 2020 21:24
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

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

Thank you @rth

if sparse.issparse(X_pred1):
X_pred1 = X_pred1.toarray()
X_pred2 = X_pred2.toarray()
assert_allclose(X_pred1, X_pred2, err_msg=err_msg)
Copy link
Member

Choose a reason for hiding this comment

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

We can use sklearn.utils._testing.assert_allclose_dense_sparse here.

@rth rth changed the title Common check for sample weight invariance with removed samples (updated) Common check for sample weight invariance with removed samples Jun 3, 2020
@rth rth merged commit 8feb045 into scikit-learn:master Jun 3, 2020
@rth rth deleted the inveriance-common-checks-updates branch June 3, 2020 22:30
viclafargue pushed a commit to viclafargue/scikit-learn that referenced this pull request Jun 26, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Jul 5, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Jul 5, 2020
@rth rth mentioned this pull request Jul 25, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Aug 5, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Oct 15, 2020
jayzed82 pushed a commit to jayzed82/scikit-learn that referenced this pull request Oct 22, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Nov 28, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Dec 12, 2020
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Feb 25, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Feb 25, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Mar 27, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Jun 15, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Jul 23, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Nov 10, 2021
ivannz added a commit to ivannz/scikit-learn that referenced this pull request May 15, 2022
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Jun 14, 2022
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Aug 29, 2022
ivannz added a commit to ivannz/scikit-learn that referenced this pull request Sep 5, 2022
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