Beispiel #1
0
def reconstruct(pmml, *args):
    mining_model = pmml.get_MiningModel()[0]
    targets = mining_model.get_Targets()
    model = EnsembleModel()
    model.isRescaleRequired(val=True)
    if targets:
        model.set_target_transformation(targets)
    fields, classes = model.get_data_information(pmml)
    if args:
        fields = args[0]
    segmentations = mining_model.get_Segmentation()
    model.set_multiple_model_method(segmentations.get_multipleModelMethod())
    segments = segmentations.get_Segment()
    tree_models = model.get_tree_models(segments)
    tree_objs = model.get_tree_objects(tree_models, fields, classes)
    model.set_classes(classes)
    model.set_tree_objs(tree_objs)
    model.n_features_ = len(fields)
    extension_value = pmml.get_MiningBuildTask().get_Extension()[0].get_value()
    if 'XGBRegressor' in extension_value:
        mod = XGBRegressor()
        mod.rescaleConstant = model.get_rescale_Constant(targets)
    elif 'GradientBoostingRegressor' in extension_value:
        mod = GradientBoostingRegressor()
        mod.rescaleFactor = model.get_rescale_Factor(targets)
        mod.rescaleConstant = model.get_rescale_Constant(targets)
    elif 'RandomForestClassifier' in extension_value:
        mod = RandomForestClassifier()
    elif 'RandomForestRegressor' in extension_value:
        mod = RandomForestRegressor()
    elif 'LGBMRegressor' in extension_value:
        mod = LGBMRegressor()
        model.isRescaleRequired(val=False)
    elif 'LGBMClassifier' in extension_value:
        mod = LGBMClassifier()
    elif 'XGBClassifier' in extension_value:
        mod = XGBClassifier()
    elif 'GradientBoostingClassifier' in extension_value:
        mod = GradientBoostingClassifier()
        mod.normalizationMethod = model.normalizationMethod
    mod.predict = model.predict
    mod.multiple_model_method = model.multiple_model_method
    mod.trees = model.trees
    mod.transformedOutputs = model.transformedOutputs
    mod.classes = model.classes
    return mod
Beispiel #2
0
def reconstruct(pmml, *args):
    mining_model = pmml.get_MiningModel()[0]
    targets = mining_model.get_Targets()
    model = EnsembleModel()
    model.isRescaleRequired(val=True)
    if targets:
        model.set_target_transformation(targets)
    fields, classes = model.get_data_information(pmml)
    if args:
        fields = args[0]
    segmentations = mining_model.get_Segmentation()
    model.set_multiple_model_method(segmentations.get_multipleModelMethod())
    segments = segmentations.get_Segment()
    tree_models = model.get_tree_models(segments)
    tree_objs = model.get_tree_objects(tree_models, fields, classes)
    model.set_classes(classes)
    model.set_tree_objs(tree_objs)
    model.n_features_ = len(fields)
    #extension_value=pmml.get_MiningBuildTask().get_Extension()[0].get_value()
    # Vinay's logic
    for ext in range(len(pmml.get_MiningBuildTask().get_Extension())):
        if ('Sequential' not in pmml.get_MiningBuildTask().get_Extension()
            [ext].get_value()) and (
                pmml.get_MiningBuildTask().get_Extension()[ext].name
                == 'modelObject'):
            extension_value = pmml.get_MiningBuildTask().get_Extension(
            )[ext].get_value()
    # Vinay's logic ends
    if 'XGBRegressor' in extension_value:
        mod = XGBRegressor()
        mod.rescaleConstant = model.get_rescale_Constant(targets)
    if 'GradientBoostingRegressor' in extension_value:
        mod = GradientBoostingRegressor()
        mod.rescaleFactor = model.get_rescale_Factor(targets)
        mod.rescaleConstant = model.get_rescale_Constant(targets)
    elif 'RandomForestClassifier' in extension_value:
        mod = RandomForestClassifier()
    elif 'RandomForestRegressor' in extension_value:
        mod = RandomForestRegressor()
    elif 'ExtraTreesClassifier' in extension_value:
        mod = ExtraTreesClassifier()
    elif 'ExtraTreesRegressor' in extension_value:
        mod = ExtraTreesRegressor()
    elif 'LGBMRegressor' in extension_value:
        mod = LGBMRegressor()
        model.isRescaleRequired(val=False)
    elif 'LGBMClassifier' in extension_value:
        mod = LGBMClassifier()
    elif 'XGBClassifier' in extension_value:
        mod = XGBClassifier()
    elif 'GradientBoostingClassifier' in extension_value:
        mod = GradientBoostingClassifier()
        mod.normalizationMethod = model.normalizationMethod
    elif 'IsolationForest' in extension_value:
        normalizedScore = mining_model.Output.OutputField[
            1].Apply.get_Constant()[0].get_valueOf_()
        threshold = mining_model.Output.OutputField[3].Apply.get_Constant(
        )[0].get_valueOf_()
        model.normalizedScore = normalizedScore
        model.threshold = threshold
        mod = IsolationForest()
    if 'IsolationForest' in extension_value:
        mod.predict = model.predict_anomaly
    else:
        mod.predict = model.predict
    mod.multiple_model_method = model.multiple_model_method
    mod.trees = model.trees
    mod.transformedOutputs = model.transformedOutputs
    mod.classes = model.classes
    return mod