Common check for sample weight invariance with removed samples#17176
Common check for sample weight invariance with removed samples#17176rth merged 10 commits intoscikit-learn:masterfrom
Conversation
…t-learn#16507) Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
|
cc @NicolasHug . We need to first merge #16963 I think. Earlier version of this PR basically implemented a simpler version of that PR. |
|
I guess we need to start with #17134 then :p |
|
@NicolasHug This PR should be good now. The coverage failure doesn't look relevant. |
NicolasHug
left a comment
There was a problem hiding this comment.
Thanks @rth, a few nits but LGTM!
sklearn/utils/estimator_checks.py
Outdated
| 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 |
There was a problem hiding this comment.
while we're at it we might as well return early here instead of having the entire function in a if block?
There was a problem hiding this comment.
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).
sklearn/utils/estimator_checks.py
Outdated
| [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) |
There was a problem hiding this comment.
for consistency these could be X1 and y1
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
Co-authored-by: Nicolas Hug <contact@nicolas-hug.com>
sklearn/utils/estimator_checks.py
Outdated
| 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) |
There was a problem hiding this comment.
We can use sklearn.utils._testing.assert_allclose_dense_sparse here.
…t-learn#17176) Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…t-learn#17176) Co-Authored-By: Nicolas Hug <contact@nicolas-hug.com>
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
…ple is never a support vector
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.