def binarize(features, binarizers):
    assert(list_of_lists(features))
    num_features = len(features[0])
    if binarizers != {} and max(binarizers.keys()) >= num_features:     
        print("Binarizers keys max: ", max(binarizers.keys()))
        print("Total feature number: ", num_features)
        print("Features:", features[0])
    assert(binarizers == {} or max(binarizers.keys()) < num_features)

    binarized_cols = []
    for i in range(num_features):
        # get this column
        cur_values = [f[i] for f in features]
        # if there's a binarizer for this column
        if i in binarizers:
            binarizer = binarizers[i]
            if type(binarizer) == LabelBinarizer:
                binarized_cols.append(binarizer.transform(cur_values))
            elif type(binarizer) == MultiLabelBinarizer:
                assert(list_of_lists(cur_values))
                # MultiLabelBinarizer doesn't support unknown values -- they need to be replaced with a default value
                # we're going to use the empty list as the default value
                cur_values_default = []
                default_value = binarizer.classes_[-1]
                for a_list in cur_values:
                    new_list = list(a_list)
                    for j, val in enumerate(new_list):
                        if val not in binarizer.classes_:
                            new_list[j] = default_value
                    cur_values_default.append(tuple(new_list))

                transformed = binarizer.transform(cur_values_default)
                binarized_cols.append(transformed)
            else:
                raise NotImplementedError('this function is not implemented for type: {}'.format(type(binarizer)))
        else:
            binarized_cols.append(np.array(cur_values).reshape(len(cur_values), 1))

    assert (len(binarized_cols) == num_features), 'the number of columns after binarization must match the number of features'
    new_features = np.hstack(binarized_cols)

    return new_features
dataset/ETHPy150Open qe-team/marmot/marmot/experiment/preprocessing_utils.py/binarize/original