跳转至

Label Transform

Label Transform replaces label with designated values.

User may specify encoder to transform labels into designated values. If no specification is provided, module will automatically encodes label into categorical label values(integers) starting at 0.

Param

label_transform_param

Attributes

Classes

LabelTransformParam(label_encoder=None, label_list=None, need_run=True)

Bases: BaseParam

Define label transform param that used in label transform.

Parameters:

Name Type Description Default
label_encoder None or dict, default

Specify (label, encoded label) key-value pairs for transforming labels to new values. e.g. {"Yes": 1, "No": 0}; **new in ver 1.9: during training, input labels not found in label_encoder will retain its original value

None
label_list None or list, default

List all input labels, used for matching types of original keys in label_encoder dict, length should match key count in label_encoder, e.g. ["Yes", "No"]; **new in ver 1.9: given non-emtpy label_encoder, when label_list not provided, module will inference label types from input data

None
need_run

Specify whether to run label transform

True
Source code in federatedml/param/label_transform_param.py
44
45
46
47
48
def __init__(self, label_encoder=None, label_list=None, need_run=True):
    super(LabelTransformParam, self).__init__()
    self.label_encoder = label_encoder
    self.label_list = label_list
    self.need_run = need_run
Attributes
label_encoder = label_encoder instance-attribute
label_list = label_list instance-attribute
need_run = need_run instance-attribute
Functions
check()
Source code in federatedml/param/label_transform_param.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def check(self):
    model_param_descr = "label transform param's "

    BaseParam.check_boolean(self.need_run, f"{model_param_descr} need run ")

    if self.label_encoder is not None:
        if not isinstance(self.label_encoder, dict):
            raise ValueError(f"{model_param_descr} label_encoder should be dict type")
        if len(self.label_encoder) == 0:
            self.label_encoder = None

    if self.label_list is not None:
        if not isinstance(self.label_list, list):
            raise ValueError(f"{model_param_descr} label_list should be list type")
        if self.label_encoder and self.label_list and len(self.label_list) != len(self.label_encoder.keys()):
            raise ValueError(f"label_list's length not matching label_encoder key count.")
        if len(self.label_list) == 0:
            self.label_list = None

    LOGGER.debug("Finish label transformer parameter check!")
    return True

最后更新: 2021-11-15