Example #1
0
  def __init__(self, pmml):
    PMMLBaseRegressor.__init__(self, pmml)

    # Setup a column transformer to deal with categorical variables
    target = self.target_field.get('name')
    fields = [field for name, field in self.fields.items() if name != target]

    def encoder_for(field):
      if field.get('optype') != 'categorical':
        return 'passthrough'

      encoder = OneHotEncoder()
      encoder.categories_ = np.array([self.field_mapping[field.get('name')][1].categories])
      encoder._legacy_mode = False
      return encoder

    transformer = ColumnTransformer(
      transformers=[
        (field.get('name'), encoder_for(field), [self.field_mapping[field.get('name')][0]])
        for field in fields
        if field.tag == 'DataField'
      ]
    )

    X = np.array([[0 for field in fields if field.tag == "DataField"]])
    transformer._validate_transformers()
    transformer._validate_column_callables(X)
    transformer._validate_remainder(X)
    transformer.transformers_ = transformer.transformers
    transformer.sparse_output_ = False
    transformer._feature_names_in = None

    self.transformer = transformer
Example #2
0
    def __init__(self, pmml):
        super().__init__(pmml)

        # Setup a column transformer to deal with categorical variables
        target = self.target_field.get('name')
        fields = [
            field for name, field in self.fields.items() if name != target
        ]

        def encoder_for(field):
            if field.get('optype') != 'categorical':
                return 'passthrough'

            encoder = OneHotEncoder()
            encoder.categories_ = np.array(
                [self.field_mapping[field.get('name')][1].categories])
            encoder._legacy_mode = False
            return encoder

        transformer = ColumnTransformer(
            transformers=[(field.get('name'), encoder_for(field),
                           [self.field_mapping[field.get('name')][0]])
                          for field in fields if field.tag == 'DataField'])
        transformer.transformers_ = transformer.transformers
        transformer.sparse_output_ = False
        self.transformer = transformer