示例#1
0
    def convert(self, param: BoostingTreeModelParam, meta: BoostingTreeModelMeta,
                guest_id_mapping: Dict,
                host_id_mapping: Dict,
                arbiter_id_mapping: Dict,
                tree_plan_delimiter='_'
                ):

        feat_importance_list = list(param.feature_importances)
        tree_list = list(param.trees_)
        tree_plan = list(param.tree_plan)
        replacer = AutoReplace(guest_id_mapping, host_id_mapping, arbiter_id_mapping)

        # fp == feature importance
        for fp in feat_importance_list:
            fp.sitename = replacer.replace(fp.sitename)
            fp.fullname = replacer.replace(fp.fullname)

        for tree in tree_list:
            tree_nodes = list(tree.tree_)
            for node in tree_nodes:
                node.sitename = replacer.replace(node.sitename)

        new_tree_plan = []
        for str_tuple in tree_plan:
            param.tree_plan.remove(str_tuple)
            tree_mode, party_id = str_tuple.split(tree_plan_delimiter)
            if int(party_id) != -1:
                new_party_id = replacer.plain_replace(party_id, role=consts.HOST)
            else:
                new_party_id = party_id
            new_tree_plan.append(tree_mode+tree_plan_delimiter+new_party_id)
        param.tree_plan.extend(new_tree_plan)

        return param, meta
示例#2
0
    def convert(self, param: FeatureBinningParam, meta: FeatureBinningMeta,
                guest_id_mapping: Dict, host_id_mapping: Dict,
                arbiter_id_mapping: Dict) -> Tuple:
        header_anonymous_list = list(param.header_anonymous)
        replacer = AutoReplace(guest_id_mapping, host_id_mapping,
                               arbiter_id_mapping)

        for idx, h in enumerate(header_anonymous_list):
            param.header_anonymous[idx] = replacer.replace(h)
        return param, meta
示例#3
0
    def convert(self, param: BoostingTreeModelParam,
                meta: BoostingTreeModelMeta, guest_id_mapping: Dict,
                host_id_mapping: Dict, arbiter_id_mapping: Dict):

        feat_importance_list = list(param.feature_importances)
        tree_list = list(param.trees_)
        replacer = AutoReplace(guest_id_mapping, host_id_mapping,
                               arbiter_id_mapping)

        # fp == feature importance
        for fp in feat_importance_list:
            fp.sitename = replacer.replace(fp.sitename)
            fp.fullname = replacer.replace(fp.fullname)

        for tree in tree_list:
            tree_nodes = list(tree.tree_)
            for node in tree_nodes:
                node.sitename = replacer.replace(node.sitename)

        return param, meta
示例#4
0
    def convert(self, param: FeatureSelectionParam, meta: FeatureSelectionMeta,
                guest_id_mapping: Dict, host_id_mapping: Dict,
                arbiter_id_mapping: Dict) -> Tuple:
        replacer = AutoReplace(guest_id_mapping, host_id_mapping,
                               arbiter_id_mapping)

        host_col_name_objs = list(param.host_col_names)
        for col_obj in host_col_name_objs:
            old_party_id = col_obj.party_id
            col_obj.party_id = str(host_id_mapping[int(old_party_id)])
            col_names = list(col_obj.col_names)

            for idx, col_name in enumerate(col_names):
                col_obj.col_names[idx] = replacer.replace(col_name)

        filter_results = list(param.results)
        new_results = []
        for idx, result in enumerate(filter_results):
            host_feature_values = list(result.host_feature_values)
            new_feature_value_list = []
            for this_host in host_feature_values:
                feature_values = dict(this_host.feature_values)
                new_feature_values = {
                    replacer.replace(k): v
                    for k, v in feature_values.items()
                }
                new_feature_value_list.append(
                    FeatureValue(feature_values=new_feature_values))

            left_col_list = list(result.host_left_cols)
            new_host_left_col = []
            for left_col_obj in left_col_list:
                original_cols = [
                    replacer.replace(x) for x in left_col_obj.original_cols
                ]
                left_cols = {
                    replacer.replace(k): v
                    for k, v in dict(left_col_obj.left_cols).items()
                }
                new_host_left_col.append(
                    LeftCols(original_cols=original_cols, left_cols=left_cols))
            new_result = FeatureSelectionFilterParam(
                feature_values=result.feature_values,
                host_feature_values=new_feature_value_list,
                left_cols=result.left_cols,
                host_left_cols=new_host_left_col,
                filter_name=result.filter_name)
            new_results.append(new_result)
        param = FeatureSelectionParam(results=new_results,
                                      final_left_cols=param.final_left_cols,
                                      col_names=param.col_names,
                                      host_col_names=param.host_col_names,
                                      header=param.header)
        return param, meta
示例#5
0
 def convert(self, param: PearsonModelParam, meta: PearsonModelMeta,
             guest_id_mapping: Dict, host_id_mapping: Dict,
             arbiter_id_mapping: Dict):
     replacer = AutoReplace(guest_id_mapping, host_id_mapping,
                            arbiter_id_mapping)
     param.party = replacer.party_tuple_format(param.party)
     for i in range(len(param.parties)):
         param.parties[i] = replacer.party_tuple_format(param.parties[i])
     for anonymous in param.anonymous_map:
         anonymous.anonymous = replacer.anonymous_format(
             anonymous.anonymous)
     for names in param.all_names:
         for i, name in enumerate(names.names):
             names.names[i] = replacer.maybe_anonymous_format(name)
     return param, meta