You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
KBinsDiscretizer.transform mutates the _encoder attribute #12490
Yes, although I am not sure it's necessary because we pass the categories to the constructor so the _encoder should be stateless. To be investigated.
I think our OneHotEncoder can't transform without fit, even though we've provided it with sufficient information.
I'm wondering why this is not detected by the common test but I don't have time to investigate now. So contributors here please try to investigate our common test.
@ogrisel I eventually recall that we choose to fit the OneHotEncoder in transform because we only determine the bins in fit. We need to put data into different bins before feeding it to OneHotEncoder.
(1) The common test fail to detect it because we use .copy() to copy the dictionary (See #12514 (comment)).
(2) There's another bug here, we can't inverse_transform after fit.
(3) We can't fit the encoder in fit because we don't put data into different bins in fit.
(4) We need to store the encoder because we need it in inverse_transform.
I'm unable to figure out a good solution (maybe some code refactoring?)
changed the title [-]KBinsDiscretizer.fransform mutates the _encoder attribute[/-][+]KBinsDiscretizer.transform mutates the _encoder attribute[/+]on Nov 4, 2018
Activity
qinhanmin2014 commentedon Oct 30, 2018
Yes, this is a problem.
If we use
self._encoder.transform, we'll need to fitself._encoderinfit.ogrisel commentedon Oct 30, 2018
Yes, although I am not sure it's necessary because we pass the categories to the constructor so the
_encodershould be stateless. To be investigated.qinhanmin2014 commentedon Oct 30, 2018
I think our
OneHotEncodercan'ttransformwithoutfit, even though we've provided it with sufficient information.I'm wondering why this is not detected by the common test but I don't have time to investigate now. So contributors here please try to investigate our common test.
grassknoted commentedon Oct 30, 2018
Hey, I'd like to work on this if no one else has taken it up yet!
ogrisel commentedon Oct 31, 2018
An issue is never "taken" :) If you don't see any linked PR, feel free to give it a try. I am not sure that this is a good first issue though. In particular you need to be very familiar with the details of the contract of the estimator API: http://scikit-learn.org/stable/developers/contributing.html#apis-of-scikit-learn-objects
jnothman commentedon Oct 31, 2018
qinhanmin2014 commentedon Nov 1, 2018
We also need it in
inverse_transform, so I guess we still need to store it.qinhanmin2014 commentedon Nov 4, 2018
So there's actually a bug in our common test (i.e., we use
.copy()instead ofdeepcopyto copy the dictionary). I've submitted a PR to fix that.qinhanmin2014 commentedon Nov 4, 2018
@ogrisel I eventually recall that we choose to fit the OneHotEncoder in transform because we only determine the bins in fit. We need to put data into different bins before feeding it to OneHotEncoder.
(1) The common test fail to detect it because we use
.copy()to copy the dictionary (See #12514 (comment)).(2) There's another bug here, we can't inverse_transform after fit.
(3) We can't fit the encoder in fit because we don't put data into different bins in fit.
(4) We need to store the encoder because we need it in inverse_transform.
I'm unable to figure out a good solution (maybe some code refactoring?)
qinhanmin2014 commentedon Nov 4, 2018
FYI I proposed an awkward solution in #12514 without refactoring the code.
[-]KBinsDiscretizer.fransform mutates the _encoder attribute[/-][+]KBinsDiscretizer.transform mutates the _encoder attribute[/+]ogrisel commentedon Nov 4, 2018
I don't understand what you mean here.
qinhanmin2014 commentedon Nov 4, 2018
@ogrisel Previously, we'll get an error if we try something like (though maybe uncommon):
because we fit the OneHotEncoder in
transform. This will be fixed in #12514MNT KBinsDiscretizer.transform should not mutate _encoder (#12514)
MNT KBinsDiscretizer.transform should not mutate _encoder (scikit-lea…
MNT KBinsDiscretizer.transform should not mutate _encoder (scikit-lea…
MNT KBinsDiscretizer.transform should not mutate _encoder (scikit-lea…
MNT KBinsDiscretizer.transform should not mutate _encoder (scikit-lea…
MNT KBinsDiscretizer.transform should not mutate _encoder (scikit-lea…
MNT KBinsDiscretizer.transform should not mutate _encoder (scikit-lea…