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

SimpleImputer strange behaviour #385

Closed
Keyeoh opened this Issue Oct 5, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@Keyeoh

Keyeoh commented Oct 5, 2018

Hi,

I am currently experiencing some weird errors while trying to port a pipeline from sklearn to dask. With respect to the SimpleImputer preprocessing class, I have noticed that the most_frequent strategy is currently implemented in such a way that the result is not what I think it should be. It reads:

def _fit_frame(self, X):
    if self.strategy == "mean":
        avg = X.mean(axis=0).values
    elif self.strategy == "median":
        avg = X.quantile().values
    elif self.strategy == "constant":
        avg = np.full(len(X.columns), self.fill_value)
    else:
        avg = [X[col].value_counts().nlargest(1).values for col in X.columns]
        avg = np.concatenate(*dask.compute(avg))

    self.statistics_ = pd.Series(dask.compute(avg)[0], index=X.columns)

My problem is with the following line:

avg = [X[col].value_counts().nlargest(1).values for col in X.columns]

I have been debugging this part and the previous line returns the counts for the most frequent item, not the item itself, which can introduce some weird errors when dealing with categorical data.

Does anybody have an explanation for this? Or did I miss something? Any hint will be much appreciated.

Regards.
Gus.

@TomAugspurger

This comment has been minimized.

Member

TomAugspurger commented Oct 7, 2018

I think you’re correct, sorry about that. We should get the .index to get the item, not the count.

TomAugspurger added a commit to TomAugspurger/dask-ml that referenced this issue Oct 15, 2018

TomAugspurger added a commit that referenced this issue Oct 15, 2018

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