-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[FIX] Preprocess: pickle when saving #2289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,12 +34,20 @@ def __call__(self, data): | |
|
||
|
||
class Continuize(Preprocess): | ||
(Indicators, FirstAsBase, FrequentAsBase, Remove, RemoveMultinomial, | ||
ReportError, AsOrdinal, AsNormalizedOrdinal, Leave) = Enum( | ||
"Continuize", | ||
"Indicators, FirstAsBase, FrequentAsBase," | ||
"Remove, RemoveMultinomial, ReportError, AsOrdinal," | ||
"AsNormalizedOrdinal, Leave") | ||
class ContinuizeDV(Enum): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can name this |
||
Indicators = "Indicators" | ||
FirstAsBase = "FirstAsBase" | ||
FrequentAsBase = "FrequentAsBase" | ||
Remove = "Remove" | ||
RemoveMultinomial = "RemoveMultinomial" | ||
ReportError = "ReportError" | ||
AsOrdinal = "AsOrdinal" | ||
AsNormalizedOrdinal = "AsNormalizedOrdinal" | ||
Leave = "Leave" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't oppose strings at all. They are simple and robust. Sklearn is all strings in params, and nobody is complaining. But sklearn checks their user input for invalid values. Could we check the passed argument is valid? E.g.: assert multinomial_treatment in self._MultinomialTreatment |
||
|
||
Indicators, FirstAsBase, FrequentAsBase, Remove, RemoveMultinomial, ReportError,\ | ||
AsOrdinal, AsNormalizedOrdinal, Leave\ | ||
= ContinuizeDV | ||
|
||
def __init__(self, zero_based=True, | ||
multinomial_treatment=Indicators): | ||
|
@@ -327,8 +335,12 @@ class Randomize(Preprocess): | |
>>> randomizer = Randomize(Randomize.RandomizeClasses) | ||
>>> randomized_data = randomizer(data) | ||
""" | ||
Type = Enum("Randomize", dict(RandomizeClasses=1, RandomizeAttributes=2, | ||
RandomizeMetas=4), type=int) | ||
from enum import IntEnum | ||
class Type(IntEnum): | ||
RandomizeClasses = 1 | ||
RandomizeAttributes = 2 | ||
RandomizeMetas = 4 | ||
|
||
RandomizeClasses, RandomizeAttributes, RandomizeMetas = Type | ||
|
||
def __init__(self, rand_type=RandomizeClasses, rand_seed=None): | ||
|
@@ -399,8 +411,16 @@ class _MethodEnum(Enum): | |
def __call__(self, *args, **kwargs): | ||
return getattr(Scale, '_' + self.name)(*args, **kwargs) | ||
|
||
CenteringType = _MethodEnum('Scale', 'NoCentering, Mean, Median') | ||
ScalingType = _MethodEnum('Scale', 'NoScaling, Std, Span') | ||
class CenteringType(_MethodEnum): | ||
NoCentering = "NoCentering" | ||
Mean = "Mean" | ||
Median = "Median" | ||
|
||
class ScalingType(_MethodEnum): | ||
NoScaling = "NoScaling" | ||
Std = "Std" | ||
Span = "Span" | ||
|
||
NoCentering, Mean, Median = CenteringType | ||
NoScaling, Std, Span = ScalingType | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before, you'd get:
With this change, it's:
Is there some way to keep the customized Enum and still pickle numbers?
Or, as an alternative, sklearn uses expressive strings. I wouldn't mind that also.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kernc: I did some changes.