BCG-X-Official / sklearndf

DataFrame support for scikit-learn.
https://bcg-x-official.github.io/sklearndf/
Apache License 2.0
63 stars 7 forks source link

[BUG] - Inverse Transform does not work for StandardScaler #182

Closed PierreOreistein closed 3 years ago

PierreOreistein commented 3 years ago

Describe the bug Hi, First of all, well done for the package. I have been using sklearndf for a couple of months and it is very handy! I notice however an issue with the Transformers. In particular, I can't apply the inverse_transform

To Reproduce For example, for StandardScalerDF, I can fit it, transform my DataFrame without issues. However, if I try to inverse the transformation, it fails.

import pandas as pd
import numpy as np
from sklearndf.transformation import StandardScalerDF

# Initialise a random DataFrame
df = pd.DataFrame(np.random.randint(1, 100, size=(10, 2)), columns=["A", "B"])
print(df)

# Instantiation and Fitting of a Standard Scaler
scaler = StandardScalerDF()
scaler.fit(df)
df = scaler.transform(df)
print(df)

# Inverse the Scaling
df = scaler.inverse_transform(df) ## ERROR --> NotFittedError: StandardScalerDF is not fitted

Did I miss anything?

Expected behavior Expect the inverse transform to be performed.

Screenshots image

First Idea where to look for I notice the usage of reset_fit() in the method inverse_transform of TransformerWrapperDF. Is it really needed? It is this command which generates the bug as it re-initializes the attribute self._features_in to None. By commenting it, it works.

Desktop :

Thank you in advance for your help,

j-ittner commented 3 years ago

Many thanks @PierreOreistein - well spotted! We'll address this in the coming days.