Talip7/scikit-learn-issues-multilabel huggingface dataset:
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
That's an interesting usecase. What do others think? @scikit-learn/core-devs

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
I'm interested in implementing this feature if @scikit-learn/core-devs decide to go in this direction.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
To add my two cents to the discussion:
> A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

I'm guessing that we should also consider adding the "robust" analog to this new `TotalVarianceScaler`, i.e. `RobustTotalVarianceScaler`. And, of course, the functional implementations, `total_variance_scale` and `robust_total_variance_scale`.

> A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

I'm not a fan of this alternative approach since it seems as a rare use case. Additionally, this would require adding the same parameter to other preprocessing functions and transformers, e.g. MinMaxScaler, MaxAbsScaler, Normalizer, etc., to keep the API consistent.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
From an implementation angle we are just reshaping the data to one column before fitting the scalar etc and this might make sense as a parameter (single_distribution?) rather than a new estimator.

But I do think it introduces complexity that would need to be justified not just through a theoretical use case, but through empirical demonstration that this actually makes a difference for learning from a dataset of more than a few points.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
> From an implementation angle we are just reshaping the data to one column before fitting the scalar etc and this might make sense as a parameter (single_distribution?) rather than a new estimator.

From an implementation viewpoint yes, but the semantics of StandardScaler and the proposed new scaler are different; not by much, but still different enough. It seems to me that the explicit classes and functions would be visible more, in the API documentation for instance, as opposed to adding the new parameter. Also, as I mentioned above, I believe that adding a new parameter will require updating other scalers (e.g. MinMaxScaler, MaxAbsScaler, Normalizer, etc.) to keep the API consistent across scalers. Finally, adding a new parameter will pollute the current interface of the `__init__` method, which is very intuitive and clean as is.

> But I do think it introduces complexity that would need to be justified not just through a theoretical use case, but through empirical demonstration that this actually makes a difference for learning from a dataset of more than a few points.

Agree.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
> It might be nice instead to have a DatasetDivider object which would be sortof like a pipeline, but instead of iteratively applying a list of transformations, it would divide the data into user-designated groups and then apply different instances of the chosen transformation (which could be a pipeline) separately to each group.

This sounds a lot like a [ColumnTransformer](https://scikit-learn.org/stable/modules/generated/sklearn.compose.ColumnTransformer.html), but maybe I'm missing something.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
Indeed, it is a lot like ColumnTransformer (sorry I didn't see it before!), though ColumnTransformer appears to be missing some key functionalities. I would love it if they were added. 

Most importantly, according to the linked documentation, ColumnTransformer seems to have no inverse_transform functionality. Why is that? Can it be remedied? It doesn't seem to me like that should be too difficult. 

Secondly, it would be really wonderful if it was possible to subset a fitted ColumnTransformer by name of the column groups or by column index, thus allowing the researcher to transform and inverse_transform a subset of the column data. Could that be implemented within the code for ColumnTransformer?

With these changes, ColumnTransformer would fulfill my needs here in combination with the StandardTotalVarianceScaler, and use of sklearn in tigramite (and other similar applications) would become as elegant as possible.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
I wouldn't mind seeing a PR adding an argument to `StandardScaler` and `RubustScaler`, to see what kind of complexity it adds to the estimators.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
It seems much easier to add additional class to the `sklearn.preprocessing` package than to change the current scalers. Something similar to the ColumnTransformer, but specific for the use-case proposed by @rebeccaherman1 seems more sensible. Here is an example implementation (did not check the code, pasting it as an idea at the moment):
```python
class GroupScaler:
    def __init__(self, base_scaler: str, *, groups: list[list[int]]=None):
        scaler_mapping = {
            'standard': StandardScaler,
            'normalize': Normalizer,
            'minmax': MinMaxScaler,
            'maxabs': MaxAbsScaler
        }
        
        self.scalers = {i: scaler_mapping[base_scaler]() for i, group in enumerate(groups)}
        self.groups = groups

    def fit(self, X, y=None):
        for i, group in enumerate(self.groups):
            self.scalers[i].fit(X[:, group].reshape(-1, 1))
        return self

    def transform(self, X):
        X_transformed = X.copy()
        for i, group in enumerate(self.groups):
            X_group = X[:, group]
            X_transformed[:, group] = self.scalers[i].transform(X_group.reshape(-1, 1)).reshape(X_group.shape)
        return X_transformed

    def fit_transform(self, X, y=None):
        return self.fit(X).transform(X)

    def inverse_transform(self, X):
        X_inversed = X.copy()
        for i, group in enumerate(self.groups):
            X_group = X[:, group]
            X_inversed[:, group] = self.scalers[i].inverse_transform(X_group.reshape(-1, 1)).reshape(X_group.shape)
        return X_inversed
```

If groups is None, the GroupScaler should behave as a single base scaler (not implemented yet).

Of course the class needs to be modified to match the scikit-learn's guidelines, but illustrates the basic idea.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
> Something similar to the ColumnTransformer, but specific for the use-case proposed by @rebeccaherman1

The ColumnTransformer is a complex beast; typically it needs to evolve to cater for all types of DataFrames. I'd rather minimize such classes. I would be more comfortable with something like the standard scaler, to be combined with the ColumnTransformer.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
> The ColumnTransformer is a complex beast; typically it needs to evolve to cater for all types of DataFrames. I'd rather minimize such classes. I would be more comfortable with something like the standard scaler, to be combined with the ColumnTransformer.

Yes, I agree that the number of complex classes/transformers should be minimized and avoided if possible. I did not phrase my comment precisely enough, my bad.

But, I believe, to avoid adding additional parameters to current scalers, an additional "meta-scaler", as proposed above, would be the best compromise amongst additional complexity to the API and implementation, and additional maintenance efforts.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
I think I agree with both of you that adding an additional parameter to the scalers is not the best approach.
I think I also agree with @GaelVaroquaux that it would be better to make use of the existing ColumnTransformer (which would require some modifications) in combination with the TotalVarianceScaler than to make a new similar object.

I would prefer the generality of the ColumnTransformer over the GroupScaler proposed by @fkdosilovic because I would like to be able to use such functionality also for sklearn decomposition objects, like PCA. I also, actually, like the ability to define different sklearn transformations for different columns, which could be useful when some of the data have different types (though it would be nice to have a simple helper function that would create a ColumnTransformer under the assumption that all transformations are the same using a list of indices like the syntax proposed by @fkdosilovic ).

This morning I was working on familiarizing myself with the code for ColumnTransformer to see if I might be able to propose something, but I haven't yet finished wrapping my head around exactly what's going on in there.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
We definitely don't want to add more ColumnTransformer like objects. And the parameter added to StandarScaler wouldn't support different groups. The user then would combine a ColumnTransformer with a StandardScaler which uses the whole data to calculate statistics.

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
(you would still need a Scaler that does Total variance for this to work @GaelVaroquaux and @adrinjalali.
Otherwise, I see that the ColumnTransformer has a weight input, but I don't want to have to, as a user, calculate those weights from the sizes of my groups)

Labels: New Feature
Standard "Total Variance" Scaler

### Desired feature

A preprocessor that removes the mean for each feature, and then scales the total variance of the dataset, rather than the variance of each feature, to 1.

### Proposed Solution

A new preprocessor that operates like StandardScaler but automatically scales total-variance instead of the variance of individual feature

### Possible Alternatives

A new input parameter for StandardScaler that allows the user to set the variance of each feature, or which allows the user to identify groups of features to be considered individual "macro" features

### Additional context

Intended use case for situations where more than one feature (column) is associated with the same data-concept (like when including multiple points in space for sea surface temperature in the Pacific and also multiple points in space for sea level pressure in the Atlantic)

COMMENT:
I'm suggesting to add a constructor argument to StandardScaler to calculate statistics from the whole data, that would solve the issue.

Labels: New Feature