Skip to content

Add sample_weight support to StandardScaler (and friends?) #15601

Closed

Description

@amueller

Via #15583:
it would be nice to have sample_weight support in StandardScaler. I don't see how to do that for sparse data right now, though (without touching the Cython code).

Activity

  1. jnothman commented on Nov 13, 2019

    @jnothman
    Member

    Touching the cython code doesn't look that hard, but it would require deciding if we want to duplicate the functions to handle the weighted case, or whether we can reuse the exisiting code paths (risking loss in both efficiency and precision).

  2. NicolasHug commented on Nov 13, 2019

    @NicolasHug
    Member

    In #14696 we duplicate. I think it's worth it as long as the function is simple enough?

  3. lorentzenchr commented on Nov 13, 2019

    @lorentzenchr
    Member

    This would also help a "sparse" solution of #3702.

  4. amueller commented on Nov 13, 2019

    @amueller
    MemberAuthor

    Actually, I'm using a numpy/scipy based helper in my PR and I think this should be fine as long as we don't need inplace?

  5. panpiort8 commented on Nov 27, 2019

    @panpiort8
    Contributor

    I can take that issue

  6. panpiort8 commented on Nov 30, 2019

    @panpiort8
    Contributor

    Computing weighted mean and variance (for non-sparse matrix) in partial_fit requires applying _incremental_mean_and_var twice or developing new (to my knowledge) method similar to _incremental_mean_and_var, but with sample_weight (like here). I believe latter option is far better and should be dealt with another issue. What do you think, guys?

  7. jnothman commented on Dec 2, 2019

    @jnothman
    Member
  8. panpiort8 commented on Dec 5, 2019

    @panpiort8
    Contributor

    I think we should just use a non-cython variant as I did here:
    https://github.com/scikit-learn/scikit-learn/pull/15583/files#diff-ce89de6ba5554a75729d37eca95fc24dR835

    But we want StandardScaler to compute stats in incremental (batch) manner, which is, I believe, quite different.

  9. lorentzenchr commented on Feb 10, 2021

    @lorentzenchr
    Member

    #18510 and #18682 added sample_weight to StandardScaler for dense and sparse input.

  10. worthy7 commented on Oct 20, 2024

    @worthy7

    Why would this be useful for SS? How are the weights used?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions