Skip to content
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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions Orange/preprocess/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Copy link
Contributor

@kernc kernc May 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before, you'd get:

>>> from Orange.preprocess import Continuize
>>> preproc = Continuize(multinomial_treatment=Continuize.FrequentAsBase)
>>> preproc
Continuize(multinomial_treatment=Continuize.FrequentAsBase)

With this change, it's:

>>> preproc = Continuize(multinomial_treatment=Continuize.FrequentAsBase)
>>> preproc
Continuize(multinomial_treatment=2)

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can name this MultinomialTreatment is it's an enumeration of such methods?

Indicators = "Indicators"
FirstAsBase = "FirstAsBase"
FrequentAsBase = "FrequentAsBase"
Remove = "Remove"
RemoveMultinomial = "RemoveMultinomial"
ReportError = "ReportError"
AsOrdinal = "AsOrdinal"
AsNormalizedOrdinal = "AsNormalizedOrdinal"
Leave = "Leave"
Copy link
Contributor

@kernc kernc Jun 12, 2017

Choose a reason for hiding this comment

The 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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down