Skip to content

Fix elasticnect cv sample weight #29442

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

Conversation

snath-xoc
Copy link
Contributor

@snath-xoc snath-xoc commented Jul 9, 2024

Fixes #22914

What does this implement/fix? Explain your changes.

Adapted from the pull request #23045 by s-banach and #29308 from snath-xoc

Modifies _alpha_grid function in linear_model._coordinate_descent to accept a sample_weight argument and implements changes to be compatible with _preprocess_data

TODO

  • Check why test_enet_cv_sample_weight_correctness fails for 6-csc_matrix-True and 6-csc_array-True

s-banach and others added 24 commits April 3, 2022 22:11
It seems like this single call to _preprocess_data suffices in all cases.
This tiny example was given in scikit-learn#22914.
The test merely asserts that alpha_max is large enough to force the coefficient to 0.
As per reviewer's suggestions:
(1) Clarify eps=1.
(2) Parameterize `fit_intercept`.
(1) Give the name `n_samples` to the quantity `X.shape[0]`.
(2) Clarify that `y_offset` and `X_scale` are not used, since these are already applied to the data by `_preprocess_data`.
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
…ied alpha_grid_ to accommodate for MultitaskCV y shape
…ear_model/tests/test_coordinate_descent/test_enet_cv_sample_weight_correctness
Copy link

github-actions bot commented Jul 9, 2024

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 080c846. Link to the linter CI: here

@ogrisel ogrisel mentioned this pull request Aug 7, 2024
1 task
test_enet_cv_sample_weight_correctness
snath-xoc and others added 2 commits August 21, 2024 10:49
test_lasso_cv
test_enet_alpha_max_sample_weight
test_enet_cv_sample_weight_correctness
Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

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

A final pass of feedback. Once addressed, LGTM for merge.

@ogrisel
Copy link
Member

ogrisel commented Sep 5, 2024

Similarly to LogisticRegressionCV, LinearModelCV has the following estimator tag:

    def _more_tags(self):
        # Note: check_sample_weights_invariance(kind='ones') should work, but
        # currently we can only mark a whole test as xfail.
        return {
            "_xfail_checks": {
                "check_sample_weights_invariance": (
                    "zero sample_weight is not equivalent to removing samples"
                ),
            }
        }

but this cannot be removed without changing check_sample_weights_invariance as explained in #29419 (comment).

snath-xoc and others added 2 commits September 6, 2024 10:52
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
@ogrisel
Copy link
Member

ogrisel commented Sep 6, 2024

@snath-xoc I pushed a quick fix for the linting problem that resulted from the merge of one of my github-edited suggestion.

The following comment still need be addressed before final review / merge:

#29442 (comment)

@ogrisel
Copy link
Member

ogrisel commented Sep 9, 2024

@snath-xoc for information I pushed 2b99c9b to address the remaining unaddressed review comment (#29442 (comment)).

This PR LGTM.

@ogrisel ogrisel added the Waiting for Second Reviewer First reviewer is done, need a second one! label Sep 9, 2024
@ogrisel
Copy link
Member

ogrisel commented Sep 9, 2024

Ooops, I did not re-run the test with all admissible random seeds... Let me fix this.

Copy link
Member

@jeremiedbb jeremiedbb left a comment

Choose a reason for hiding this comment

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

LGTM, thanks !

@jeremiedbb jeremiedbb merged commit cc00420 into scikit-learn:main Sep 9, 2024
30 checks passed
MarcBresson pushed a commit to MarcBresson/scikit-learn that referenced this pull request Sep 19, 2024
Co-authored-by: Mr. Snrub <45150804+s-banach@users.noreply.github.com>
Co-authored-by: Olivier Grisel <olivier.grisel@ensta.org>
Co-authored-by: Shruti Nath <shrutinath@Shrutis-Laptop.local>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:linear_model Waiting for Second Reviewer First reviewer is done, need a second one!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Calculation of alphas in ElasticNetCV doesn't use sample_weight
4 participants