Skip to content

Commit

Permalink
Minibatch: Add one-hot encoding option for int
Browse files Browse the repository at this point in the history
JIRA: MADLIB-1226

Integer dependent variables can be used either in regression or
classification. To use in classification, they need to be one-hot
encoded. This commit adds an option to allow users to pick if a integer
dependent input needs to one-hot encoded or not. The flag is ignored if
the variable is not of integer type.

Other changes include adding an appropriate test in install-check,
code cleanup and PEP8 conformance.
  • Loading branch information
iyerr3 committed Apr 11, 2018
1 parent 3e519dc commit d9381e2
Show file tree
Hide file tree
Showing 6 changed files with 302 additions and 205 deletions.
32 changes: 27 additions & 5 deletions src/ports/postgres/modules/utilities/control.py_in
Expand Up @@ -10,21 +10,43 @@ m4_changequote(`<!', `!>')

@brief driver functions shared by modules
"""
import plpy

from distutils.util import strtobool
import plpy
from functools import wraps

from utilities import __mad_version
version_wrapper = __mad_version()
from utilities import unique_string
_unique_string = unique_string


STATE_IN_MEM = m4_ifdef(<!__HAWQ__!>, <!True!>, <!False!>)
HAS_FUNCTION_PROPERTIES = m4_ifdef(<!__HAS_FUNCTION_PROPERTIES__!>, <!True!>, <!False!>)
UDF_ON_SEGMENT_NOT_ALLOWED = m4_ifdef(<!__UDF_ON_SEGMENT_NOT_ALLOWED__!>, <!True!>, <!False!>)


# from https://coderwall.com/p/0lk6jg/python-decorators-vs-context-managers-have-your-cake-and-eat-it
class ContextDecorator(object):
""" Class to use a context manager also as a decorator

Inherit context manager classes from this class to use as a decorator
"""
def __init__(self, **kwargs):
self.__dict__.update(kwargs)

def __enter__(self):
# Note: Returning self means that in "with ... as x", x will be self
return self

def __exit__(self, typ, val, traceback):
pass

def __call__(self, f):
@wraps(f)
def wrapper(*args, **kw):
with self:
return f(*args, **kw)
return wrapper


class OptimizerControl(object):

"""
Expand Down Expand Up @@ -112,7 +134,7 @@ class HashaggControl(object):
format(('off', 'on')[self.hashagg_enabled]))


class MinWarning:
class MinWarning(ContextDecorator):

"""
@brief A wrapper for setting the level of logs going into client
Expand Down

0 comments on commit d9381e2

Please sign in to comment.