Exemplo n.º 1
0
    def test_pipeline_regression_creation(self):

        input_names = self.scikit_data.feature_names
        output_name = 'target'
        p_regressor = PipelineRegressor(input_names, 'target')
        p_regressor.add_model(self.scikit_spec)

        self.assertIsNotNone(p_regressor.spec)
        self.assertEqual(
            len(p_regressor.spec.pipelineRegressor.pipeline.models), 1)

        # Test the model class of the linear regressor model
        spec = p_regressor.spec.pipelineRegressor.pipeline.models[0]
        self.assertIsNotNone(spec.description)

        # Test the interface class
        self.assertEqual(spec.description.predictedFeatureName, 'target')

        # Test the inputs and outputs
        self.assertEqual(len(spec.description.output), 1)
        self.assertEqual(spec.description.output[0].name, 'target')
        self.assertEqual(spec.description.output[0].type.WhichOneof('Type'),
                         'doubleType')
        for input_type in spec.description.input:
            self.assertEqual(input_type.type.WhichOneof('Type'), 'doubleType')
        self.assertEqual(sorted(input_names),
                         sorted(map(lambda x: x.name, spec.description.input)))
Exemplo n.º 2
0
    def test_pipeline_regressor_make_updatable(self):
        builder = self.create_base_builder()
        builder.spec.isUpdatable = False

        training_input = [("input", datatypes.Array(3)), ("target", "Double")]

        # fails due to missing sub-models
        p_regressor = PipelineRegressor(self.input_features, self.output_names,
                                        training_input)
        with self.assertRaises(ValueError):
            p_regressor.make_updatable()
        self.assertEqual(p_regressor.spec.isUpdatable, False)

        # fails due to sub-model being not updatable
        p_regressor.add_model(builder.spec)
        with self.assertRaises(ValueError):
            p_regressor.make_updatable()
        self.assertEqual(p_regressor.spec.isUpdatable, False)

        builder.spec.isUpdatable = True
        p_regressor.add_model(builder.spec)

        self.assertEqual(p_regressor.spec.isUpdatable, False)
        p_regressor.make_updatable()
        self.assertEqual(p_regressor.spec.isUpdatable, True)
        self.assertEqual(p_regressor.spec.description.trainingInput[0].name,
                         "input")
        self.assertEqual(
            p_regressor.spec.description.trainingInput[0].type.WhichOneof(
                "Type"),
            "multiArrayType",
        )
        self.assertEqual(p_regressor.spec.description.trainingInput[1].name,
                         "target")
        self.assertEqual(
            p_regressor.spec.description.trainingInput[1].type.WhichOneof(
                "Type"),
            "doubleType",
        )

        # fails since once updatable does not allow adding new models
        with self.assertRaises(ValueError):
            p_regressor.add_model(builder.spec)
        self.assertEqual(p_regressor.spec.isUpdatable, True)