Skip to content

label_transform_param

label_transform_param

Classes

LabelTransformParam (BaseParam)

Define label transform param that used in label transform.

Parameters:

Name Type Description Default
label_encoder None or dict, default : None

Specify (label, encoded label) key-value pairs for transforming labels to new values. e.g. {"Yes": 1, "No": 0}

None
label_list None or list, default : None

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"]

None
need_run bool, default: True

Specify whether to run label transform

True
Source code in federatedml/param/label_transform_param.py
class LabelTransformParam(BaseParam):
    """
    Define label transform param that used in label transform.

    Parameters
    ----------

    label_encoder : None or dict, default : None
        Specify (label, encoded label) key-value pairs for transforming labels to new values.
        e.g. {"Yes": 1, "No": 0}

    label_list : None or list, default : None
        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"]

    need_run: bool, default: True
        Specify whether to run label transform

    """

    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

    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 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 len(self.label_list) != len(self.label_encoder.keys()):
                raise ValueError(f"label_list length should match label_encoder key count")

        LOGGER.debug("Finish label transformer parameter check!")
        return True
__init__(self, label_encoder=None, label_list=None, need_run=True) special
Source code in federatedml/param/label_transform_param.py
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
check(self)
Source code in federatedml/param/label_transform_param.py
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 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 len(self.label_list) != len(self.label_encoder.keys()):
            raise ValueError(f"label_list length should match label_encoder key count")

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

Last update: 2021-12-03
Back to top