Esempio n. 1
0
 def init_data(self):
     np.random.seed(12363)
     self.x = pd.DataFrame(np.random.randn(500, 10))
     self.y = pd.DataFrame({
         _TARGET_NAME:
         [np.random.choice([0, 1, 2]) for _ in range(self.x.shape[0])]
     })
     self._model.fit(self.x, np.ravel(self.y))
     self.ctx = TransformationContext(
         input=[RealNumericFeature(col) for col in list(self.x)],
         derived=[],
         model=[RealNumericFeature(col) for col in list(self.x)],
         output=[self.output])
Esempio n. 2
0
 def init_data_one_label(self):
     np.random.seed(12363)
     self.x = pd.DataFrame(np.random.randn(500, 4),
                           columns=['col_' + str(_) for _ in range(4)])
     self.y = pd.DataFrame({
         TARGET_NAME:
         [np.random.choice([0, 1]) for _ in range(self.x.shape[0])]
     })
     self._model.fit(self.x, np.ravel(self.y))
     self.ctx = TransformationContext()
     self.ctx.schemas[Schema.INPUT] = [
         RealNumericFeature(col) for col in list(self.x)
     ]
     self.ctx.schemas[Schema.DERIVED] = []
     self.ctx.schemas[Schema.MODEL] = [
         RealNumericFeature(col) for col in list(self.x)
     ]
     self.ctx.schemas[Schema.OUTPUT] = [self.output]
Esempio n. 3
0
 def setUp(self):
     np.random.seed(1)
     self.est = GradientBoostingClassifier(max_depth=2, n_estimators=10)
     self.est.fit([
         [0, 0],
         [0, 1],
         [1, 0],
         [1, 1],
     ], [0, 1, 1, 1])
     self.ctx = TransformationContext(
         input=[IntegerNumericFeature('x1'), StringCategoricalFeature('x2', ['zero', 'one'])],
         derived=[],
         model=[IntegerNumericFeature('x1'), StringCategoricalFeature('x2', ['zero', 'one'])],
         output=[RealNumericFeature('output')]
     )
     self.converter = GradientBoostingConverter(
         estimator=self.est,
         context=self.ctx
     )
 def test_transform_with_derived_field(self):
     self.est = DecisionTreeClassifier(max_depth=2)
     self.est.fit([
         [0, 0, 0],
         [0, 1, 0],
         [1, 0, 0],
         [1, 1, 1],
     ], [0, 1, 1, 1])
     mapping = pmml.MapValues(dataType="double", outputColumn="output")
     mapping.append(pmml.FieldColumnPair(column="x1", field="x1"))
     mapping.append(pmml.FieldColumnPair(column="x2", field="x2"))
     it = pmml.InlineTable()
     it.append(pmml_row(x1=0, x2='zero', output=0))
     it.append(pmml_row(x1=0, x2='one', output=0))
     it.append(pmml_row(x1=1, x2='zero', output=0))
     it.append(pmml_row(x1=1, x2='one', output=1))
     mapping.append(it)
     self.ctx = TransformationContext({
         Schema.INPUT: [
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         Schema.DERIVED: [
             DerivedFeature(feature=RealNumericFeature(name='x3'),
                            transformation=mapping)
         ],
         Schema.MODEL: [
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one']),
             RealNumericFeature(name='x3')
         ],
         Schema.OUTPUT:
         [IntegerCategoricalFeature('output', ['neg', 'pos'])]
     })
     self.converter = DecisionTreeConverter(estimator=self.est,
                                            context=self.ctx,
                                            mode=ModelMode.CLASSIFICATION)
     self.converter.pmml().toxml()
Esempio n. 5
0
 def setUp(self):
     np.random.seed(1)
     self.est = GradientBoostingClassifier(max_depth=2, n_estimators=10)
     self.est.fit([
         [0, 0],
         [0, 1],
         [1, 0],
         [1, 1],
     ], [0, 1, 1, 1])
     self.ctx = TransformationContext({
         Schema.INPUT: [
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         Schema.MODEL: [
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         Schema.DERIVED: [],
         Schema.OUTPUT: [IntegerCategoricalFeature('output', [0, 1])]
     })
     self.converter = GradientBoostingConverter(estimator=self.est,
                                                context=self.ctx)
 def setUp(self):
     np.random.seed(1)
     self.est = DecisionTreeRegressor(max_depth=2)
     self.est.fit([
         [0, 0],
         [0, 1],
         [1, 0],
         [1, 1],
     ], [0, 1, 1, 1])
     self.ctx = TransformationContext({
         Schema.INPUT: [
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         Schema.MODEL: [
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         Schema.DERIVED: [],
         Schema.OUTPUT: [IntegerNumericFeature('output')]
     })
     self.converter = DecisionTreeConverter(estimator=self.est,
                                            context=self.ctx,
                                            mode=ModelMode.REGRESSION)
 def setUp(self):
     np.random.seed(1)
     self.est = DecisionTreeRegressor(max_depth=2)
     self.est.fit([
         [0, 0],
         [0, 1],
         [1, 0],
         [1, 1],
     ], [0, 1, 1, 1])
     self.ctx = TransformationContext(
         input=[
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         model=[
             IntegerNumericFeature('x1'),
             StringCategoricalFeature('x2', ['zero', 'one'])
         ],
         derived=[],
         output=[IntegerNumericFeature('output')])
     self.converter = DecisionTreeConverter(
         estimator=self.est,
         context=self.ctx,
         mode=DecisionTreeConverter.MODE_REGRESSION)