Skip to content

Column Expand

Column Expand is used for adding arbitrary number of columns with user-provided values. This module is run directly on dense table(raw data), before data entering Data Transform.

Param

column_expand_param

Attributes

Classes

ColumnExpandParam(append_header=None, method='manual', fill_value=consts.FLOAT_ZERO, need_run=True)

Bases: BaseParam

Define method used for expanding column

Parameters:

Name Type Description Default
append_header None or str or List[str], default

Name(s) for appended feature(s). If None is given, module outputs the original input value without any operation.

None
method str, default

If method is 'manual', use user-specified fill_value to fill in new features.

'manual'
fill_value int or float or str or List[int] or List[float] or List[str], default

Used for filling expanded feature columns. If given a list, length of the list must match that of append_header

consts.FLOAT_ZERO
need_run

Indicate if this module needed to be run.

True
Source code in python/federatedml/param/column_expand_param.py
41
42
43
44
45
46
47
def __init__(self, append_header=None, method="manual",
             fill_value=consts.FLOAT_ZERO, need_run=True):
    super(ColumnExpandParam, self).__init__()
    self.append_header = append_header
    self.method = method
    self.fill_value = fill_value
    self.need_run = need_run
Attributes
append_header = append_header instance-attribute
method = method instance-attribute
fill_value = fill_value instance-attribute
need_run = need_run instance-attribute
Functions
check()
Source code in python/federatedml/param/column_expand_param.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
def check(self):
    descr = "column_expand param's "
    if not isinstance(self.method, str):
        raise ValueError(f"{descr}method {self.method} not supported, should be str type")
    else:
        user_input = self.method.lower()
        if user_input == "manual":
            self.method = consts.MANUAL
        else:
            raise ValueError(f"{descr} method {user_input} not supported")

    BaseParam.check_boolean(self.need_run, descr=descr)

    self.append_header = [] if self.append_header is None else self.append_header
    if not isinstance(self.append_header, list):
        raise ValueError(f"{descr} append_header must be None or list of str. "
                         f"Received {type(self.append_header)} instead.")
    for feature_name in self.append_header:
        BaseParam.check_string(feature_name, descr + "append_header values")

    if isinstance(self.fill_value, list):
        if len(self.append_header) != len(self.fill_value):
            raise ValueError(
                f"{descr} `fill value` is set to be list, "
                f"and param `append_header` must also be list of the same length.")
    else:
        self.fill_value = [self.fill_value]
    for value in self.fill_value:
        if type(value).__name__ not in ["float", "int", "long", "str"]:
            raise ValueError(
                f"{descr} fill value(s) must be float, int, or str. Received type {type(value)} instead.")

    LOGGER.debug("Finish column expand parameter check!")
    return True

Last update: 2022-07-12