Esempio n. 1
0
    def segmentation(self):
        """
        Build a segmentation (sequence of estimators)
        :return: Segmentation element
        """
        # there is no notion of weighted sum, so we should take weighted average and multiply result by total weight
        # in output transformation
        segmentation = pmml.Segmentation(multipleModelMethod="weightedAverage")

        # build the context for the nested regression models by replacing output categorical feature
        # with the continuous numeric feature
        regression_context = copy(self.context)
        regression_context.schemas[Schema.OUTPUT] = [
            RealNumericFeature(
                name=self.context.schemas[Schema.OUTPUT][0].name,
                namespace=Schema.NUMERIC.value)
        ]

        # first, transform initial estimator
        init_segment = pmml.Segment(weight=1)
        init_segment.append(pmml.True_())
        init_segment.append(
            find_converter(self.estimator.init_)(self.estimator.init_,
                                                 regression_context).model())
        segmentation.append(init_segment)

        for est in self.estimator.estimators_[:, 0]:
            s = pmml.Segment(weight=self.estimator.learning_rate)
            s.append(pmml.True_())
            s.append(
                DecisionTreeConverter(est, regression_context,
                                      ModelMode.REGRESSION)._model())
            segmentation.append(s)

        return segmentation
Esempio n. 2
0
    def segmentation(self):
        """
        Build a segmentation (sequence of estimators)
        :return: Segmentation element
        """
        # there is no notion of weighted sum, so we should take weighted average and multiply result by total weight
        # in output transformation
        segmentation = pmml.Segmentation(multipleModelMethod="weightedAverage")

        # build the context for the nested regression models by replacing output categorical feature
        # with the continuous numeric feature
        regression_context = TransformationContext(schemas=dict(self.context.schemas))
        regression_context.schemas[Schema.OUTPUT] = [RealNumericFeature(
            name=self.context.schemas[Schema.OUTPUT][0].name,
            namespace=Schema.NUMERIC.namespace
        )]

        # first, transform initial estimator
        init_segment = pmml.Segment(weight=1)
        init_segment.append(pmml.True_())
        init_segment.append(find_converter(self.estimator.init_)(self.estimator.init_, regression_context).model())
        segmentation.append(init_segment)

        for est in self.estimator.estimators_[:, 0]:
            s = pmml.Segment(weight=self.estimator.learning_rate)
            s.append(pmml.True_())
            s.append(DecisionTreeConverter(est, regression_context, ModelMode.REGRESSION)._model())
            segmentation.append(s)

        return segmentation
Esempio n. 3
0
    def segmentation(self):
        """
        Build a segmentation (sequence of estimators)
        :return: Segmentation element
        """
        # there is no notion of weighted sum, so we should take weighted average and multiply result by total weight
        # in output transformation
        segmentation = pmml.Segmentation(multipleModelMethod="weightedAverage")

        # first, transform initial estimator
        init_segment = pmml.Segment(weight=1)
        init_segment.append(pmml.True_())
        init_segment.append(
            find_converter(self.estimator.init_)(self.estimator.init_,
                                                 self.context).model())
        segmentation.append(init_segment)

        for est in self.estimator.estimators_[:, 0]:
            s = pmml.Segment(weight=self.estimator.learning_rate)
            s.append(pmml.True_())
            s.append(
                DecisionTreeConverter(est, self.context,
                                      self.MODE_REGRESSION)._model())
            segmentation.append(s)

        return segmentation
Esempio n. 4
0
    def __init__(self, estimator, context):
        super(GradientBoostingConverter, self).__init__(estimator, context, self.MODE_CLASSIFICATION)

        assert isinstance(estimator, GradientBoostingClassifier), \
            'This converter can only process GradientBoostingClassifier instances'
        assert len(context.schemas[self.SCHEMA_OUTPUT]) == 1, 'Only one-label classification is supported'
        assert not estimator.loss_.is_multi_class, 'Only one-label classification is supported'
        assert context.schemas[self.SCHEMA_OUTPUT][0].data_type == 'double', 'PMML version only returns probabilities'
        assert context.schemas[self.SCHEMA_OUTPUT][0].optype == 'continuous', 'PMML version only returns probabilities'
        assert find_converter(estimator.init_) is not None, 'Can not find a converter for {}'.format(estimator.init_)
Esempio n. 5
0
    def __init__(self, estimator, context):
        super(GradientBoostingConverter, self).__init__(estimator, context)

        assert isinstance(estimator, GradientBoostingClassifier), \
            'This converter can only process GradientBoostingClassifier instances'
        assert len(context.schemas[Schema.OUTPUT]) == 1, 'Only one-label classification is supported'
        assert not estimator.loss_.is_multi_class, 'Only one-label classification is supported'
        assert context.schemas[Schema.OUTPUT][0].optype == FeatureOpType.CATEGORICAL, \
            'Classification output must be categorical'
        assert len(context.schemas[Schema.OUTPUT][0].value_list) == 2, 'Only binary classifier is supported'
        assert find_converter(estimator.init_) is not None, 'Can not find a converter for {}'.format(estimator.init_)
Esempio n. 6
0
    def __init__(self, estimator, context):
        super(GradientBoostingConverter, self).__init__(estimator, context)

        assert isinstance(estimator, GradientBoostingClassifier), \
            'This converter can only process GradientBoostingClassifier instances'
        assert len(context.schemas[
            Schema.OUTPUT]) == 1, 'Only one-label classification is supported'
        assert not estimator.loss_.is_multi_class, 'Only one-label classification is supported'
        assert context.schemas[Schema.OUTPUT][0].optype == FeatureOpType.CATEGORICAL, \
            'Classification output must be categorical'
        assert len(context.schemas[Schema.OUTPUT]
                   [0].value_list) == 2, 'Only binary classifier is supported'
        assert find_converter(
            estimator.init_
        ) is not None, 'Can not find a converter for {}'.format(
            estimator.init_)
Esempio n. 7
0
    def __init__(self, estimator, context):
        super(GradientBoostingConverter,
              self).__init__(estimator, context, self.MODE_CLASSIFICATION)

        assert isinstance(estimator, GradientBoostingClassifier), \
            'This converter can only process GradientBoostingClassifier instances'
        assert len(context.schemas[self.SCHEMA_OUTPUT]
                   ) == 1, 'Only one-label classification is supported'
        assert not estimator.loss_.is_multi_class, 'Only one-label classification is supported'
        assert context.schemas[self.SCHEMA_OUTPUT][
            0].data_type == 'double', 'PMML version only returns probabilities'
        assert context.schemas[self.SCHEMA_OUTPUT][
            0].optype == 'continuous', 'PMML version only returns probabilities'
        assert find_converter(
            estimator.init_
        ) is not None, 'Can not find a converter for {}'.format(
            estimator.init_)
Esempio n. 8
0
    def segmentation(self):
        """
        Build a segmentation (sequence of estimators)
        :return: Segmentation element
        """
        # there is no notion of weighted sum, so we should take weighted average and multiply result by total weight
        # in output transformation
        segmentation = pmml.Segmentation(multipleModelMethod="weightedAverage")

        # first, transform initial estimator
        init_segment = pmml.Segment(weight=1)
        init_segment.append(pmml.True_())
        init_segment.append(find_converter(self.estimator.init_)(self.estimator.init_, self.context).model())
        segmentation.append(init_segment)

        for est in self.estimator.estimators_[:, 0]:
            s = pmml.Segment(weight=self.estimator.learning_rate)
            s.append(pmml.True_())
            s.append(DecisionTreeConverter(est, self.context, self.MODE_REGRESSION)._model())
            segmentation.append(s)

        return segmentation