Skip to content

partial_fit for RobustScaler #30408

Open
Open

Description

@zaccharieramzi

Describe the workflow you want to enable

I would like to be able to use partial_fit with the RobustScaler preprocessing for streaming cases or when my data doesn't fit in memory.
As I understand from this paper https://sites.cs.ucsb.edu/~suri/psdir/ency.pdf, it would probably only be possible to compute the robustly estimated variance and mean up to some precision epsilon, that could probably become an attribute of the class.

Not sure whether this should be considered a new algorithm or not, let me know what you think.

Describe your proposed solution

I haven't looked much into it but I think there were 2 approaches:

Describe alternatives you've considered, if relevant

An alternative proposed in this SO comment is to load the data column by column if it reduces the memory load.

However, that would be super impractical in my setting where I just cannot load all data into memory at once.

Additional context

No response

Activity

  1. ogrisel commented on Dec 4, 2024

    @ogrisel
    Member

    it would probably only be possible to compute the robustly estimated variance and mean up to some precision epsilon

    Nitpicking and to avoid any confusion: RobustScaler does not estimate the mean and variance but rather the median and IQR. Those can be very different values depending on the distribution.

    Personally, I find the reservoir sampling approach interesting. Not that a subsample param similar to what we do in KBinsDiscretizer would make sense, irrespective of whether or not we implement partial_fit. It could later be reused to control the size of the reservoir sampler used for partial_fit.

    In addition to the methods referenced in the paper linked above, there is also the t-digest out-of-core / online estimator: https://github.com/tdunning/t-digest (but I have no idea about what are the pros and cons).

  2. added
    Needs Decision
    and removed
    Needs Triage
    on Dec 4, 2024
  3. ogrisel commented on Dec 4, 2024

    @ogrisel
    Member

    Not sure whether this should be considered a new algorithm or not, let me know what you think.

    We could introduce an extra algorithm or quantile_method constructor parameter for the RobustScaler class to select the strategy.

    Note that in #29907, we are introducing the quantile_method="averaged_inverted_cdf" parameter as the future default method to be able to implement the expected weight/repetition semantics when fitting KBinsDiscretizer with strategy="quantile" and sample_weight.

    We can problem reuse that parameter in RobustScaler (and also add support for sample_weight). This parameter could then be expanded to implement quantile_method="t-digest" or similar later, and some of those can be made to support partial_fit (with or without subsample).

  4. added
    Needs Decision - Include Feature
    and removed
    Needs Decision
    on Dec 4, 2024
  5. ogrisel commented on Dec 4, 2024

    @ogrisel
    Member

    Thinking about it, the reservoir sampling approach might not be robust if the data is not i.i.d. or exchangeable, and might as a result lead to very different values that depend on the ordering of the data passed to successive partial_fit calls. Other methods are probably more robust to this problem.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs Decision - Include FeatureNew Feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions