예제 #1
0
def lightgbm_parser(scope, model, inputs, custom_parsers=None):
    if hasattr(model, "fit"):
        raise TypeError(  # pragma: no cover
            "This converter does not apply on type '{}'."
            "".format(type(model)))

    if len(inputs) == 1:
        wrapped = WrappedBooster(model)
        objective = wrapped.get_objective()
        if objective.startswith('binary'):
            wrapped = WrappedLightGbmBoosterClassifier(wrapped)
            return _parse_sklearn_classifier(
                scope, wrapped, inputs, custom_parsers=custom_parsers)
        if objective.startswith('multiclass'):
            wrapped = WrappedLightGbmBoosterClassifier(wrapped)
            return _parse_sklearn_classifier(
                scope, wrapped, inputs, custom_parsers=custom_parsers)
        if objective.startswith('regression'):  # pragma: no cover
            return _parse_sklearn_simple_model(
                scope, wrapped, inputs, custom_parsers=custom_parsers)
        raise NotImplementedError(  # pragma: no cover
            "Objective '{}' is not implemented yet.".format(objective))

    # Multiple columns
    this_operator = scope.declare_local_operator('LightGBMConcat')
    this_operator.raw_operator = model
    this_operator.inputs = inputs
    var = scope.declare_local_variable(
        'Xlgbm', inputs[0].type.__class__([None, None]))
    this_operator.outputs.append(var)
    return lightgbm_parser(scope, model, this_operator.outputs,
                           custom_parsers=custom_parsers)
예제 #2
0
 def custom_parser(scope, model, inputs, custom_parsers=None):
     if custom_parsers is not None and model in custom_parsers:
         return custom_parsers[model](
             scope, model, inputs, custom_parsers=custom_parsers)
     if not all(isinstance(i, (numbers.Real, bool, np.bool_))
                for i in model.classes_):
         raise NotImplementedError(
             "Current converter does not support string labels.")
     return _parse_sklearn_classifier(scope, model, inputs)
예제 #3
0
def _custom_parser_xgboost(scope, model, inputs, custom_parsers=None):
    """
    Custom parser for *XGBClassifier* and *LGBMClassifier*.
    """
    if custom_parsers is not None and model in custom_parsers:
        return custom_parsers[model](
            scope, model, inputs, custom_parsers=custom_parsers)
    if not all(isinstance(i, (numbers.Real, bool, numpy.bool_))
               for i in model.classes_):
        raise NotImplementedError(  # pragma: no cover
            "Current converter does not support string labels.")
    try:
        from skl2onnx._parse import _parse_sklearn_classifier
    except ImportError as e:
        import skl2onnx
        raise ImportError(
            "Hidden API has changed in module 'skl2onnx=={}', "
            "installation path is '{}'.".format(
                skl2onnx.__version__, skl2onnx.__file__)) from e
    return _parse_sklearn_classifier(scope, model, inputs)