How to use mlblocks - 10 common examples

To help you get started, we’ve selected a few mlblocks examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github HDI-Project / MLBlocks / tests / features / test_partial_outputs.py View on Github external
def test_fit_output(self):

        # Setup variables
        primitives = [
            'sklearn.preprocessing.StandardScaler',
            'sklearn.linear_model.LogisticRegression'
        ]
        pipeline = MLPipeline(primitives)

        named = 'default'
        list_ = ['default', 0]
        int_block = 0
        invalid_int = 10
        str_block = 'sklearn.preprocessing.StandardScaler#1'
        invalid_block = 'InvalidBlockName'
        str_block_variable = 'sklearn.preprocessing.StandardScaler#1.X'
        invalid_variable = 'sklearn.preprocessing.StandardScaler#1.invalid'

        # Run
        named_out = pipeline.fit(self.X, self.y, output_=named)
        list_out = pipeline.fit(self.X, self.y, output_=list_)
        int_out = pipeline.fit(self.X, self.y, output_=int_block)
        str_out = pipeline.fit(self.X, self.y, output_=str_block)
        str_out_variable = pipeline.fit(self.X, self.y,
github HDI-Project / MLBlocks / tests / features / test_partial_outputs.py View on Github external
def test_predict_start(self):
        # Setup variables
        primitives = [
            'sklearn.preprocessing.StandardScaler',
            'sklearn.linear_model.LogisticRegression'
        ]
        pipeline = MLPipeline(primitives)
        pipeline.fit(self.X, self.y)

        # Mock the first block
        block_mock = Mock()
        pipeline.blocks['sklearn.preprocessing.StandardScaler#1'] = block_mock

        # Run first block
        context = {
            'X': self.X,
        }
        int_start = 1
        str_start = 'sklearn.linear_model.LogisticRegression#1'

        pipeline.predict(start_=int_start, **context)
        pipeline.predict(start_=str_start, **context)
github HDI-Project / MLBlocks / tests / test_mlpipeline.py View on Github external
outputs = {
            'default': [
                {
                    'name': 'a_name',
                    'variable': 'a_variable',
                    'type': 'a_type',
                }
            ],
            'debug': [
                {
                    'name': 'another_name',
                    'variable': 'another_variable',
                }
            ]
        }
        pipeline = MLPipeline(['a_primitive', 'another_primitive'], outputs=outputs)

        pipeline.blocks['a_primitive#1'].produce_output = [
            {
                'name': 'output',
                'type': 'whatever'
            }
        ]
        pipeline.blocks['another_primitive#1'].produce_output = [
            {
                'name': 'something',
            }
        ]

        returned = pipeline.get_outputs(['default', 'debug', -1, 'a_primitive#1.output'])

        expected = [
github HDI-Project / MLBlocks / tests / test_mlpipeline.py View on Github external
def test_get_tunable_hyperparameters(self):
        mlpipeline = MLPipeline(['a_primitive'])
        tunable = dict()
        mlpipeline._tunable_hyperparameters = tunable

        returned = mlpipeline.get_tunable_hyperparameters()

        assert returned == tunable
        assert returned is not tunable
github HDI-Project / MLBlocks / tests / test_mlpipeline.py View on Github external
def test__get_block_args(self):
        input_names = {
            'a_block': {
                'arg_3': 'arg_3_alt'
            }
        }
        pipeline = MLPipeline(['a_primitive'], input_names=input_names)

        block_args = [
            {
                'name': 'arg_1',
            },
            {
                'name': 'arg_2',
                'default': 'arg_2_value'
            },
            {
                'name': 'arg_3',
            },
            {
                'name': 'arg_4',
                'required': False
            },
github HDI-Project / MLBlocks / tests / test_mlpipeline.py View on Github external
def test_get_tunable_hyperparameters_flat(self):
        mlpipeline = MLPipeline(['a_primitive'])
        mlpipeline._tunable_hyperparameters = {
            'block_1': {
                'hp_1': {
                    'type': 'int',
                    'range': [
                        1,
                        10
                    ],
                }
            },
            'block_2': {
                'hp_1': {
                    'type': 'str',
                    'default': 'a',
                    'values': [
                        'a',
github HDI-Project / MLBlocks / tests / test_mlpipeline.py View on Github external
def test_get_output_variables(self):
        outputs = {
            'default': [
                {
                    'name': 'a_name',
                    'variable': 'a_variable',
                    'type': 'a_type',
                }
            ]
        }
        pipeline = MLPipeline(['a_primitive'], outputs=outputs)

        names = pipeline.get_output_variables()

        assert names == ['a_variable']
github HDI-Project / MLBlocks / tests / test_mlpipeline.py View on Github external
def test_get_output_names(self):
        outputs = {
            'default': [
                {
                    'name': 'a_name',
                    'variable': 'a_variable',
                    'type': 'a_type',
                }
            ]
        }
        pipeline = MLPipeline(['a_primitive'], outputs=outputs)

        names = pipeline.get_output_names()

        assert names == ['a_name']
github HDI-Project / MLBlocks / tests / test_mlblock.py View on Github external
def test___init__(self, load_primitive_mock, import_object_mock, set_hps_mock):
        load_primitive_mock.return_value = {
            'name': 'a_primitive_name',
            'primitive': 'a_primitive_name',
            'produce': {
                'args': [
                    {
                        'name': 'argument'
                    }
                ],
                'output': [
                ]
            }
        }

        mlblock = MLBlock('a_primitive_name', argument='value')

        assert mlblock.metadata == {
            'name': 'a_primitive_name',
            'primitive': 'a_primitive_name',
            'produce': {
                'args': [
                    {
                        'name': 'argument'
                    }
                ],
                'output': [
                ]
            }
        }
        assert mlblock.name == 'a_primitive_name'
        assert mlblock.primitive == import_object_mock.return_value
github HDI-Project / MLBlocks / tests / test_mlblock.py View on Github external
# setup
        init_params = {
            'an_init_param': 'a_value'
        }
        hyperparameters = {
            'tunable': {
                'this_is_not_conditional': {
                    'type': 'int',
                    'default': 1,
                    'range': [1, 10]
                }
            }
        }

        # run
        tunable = MLBlock._get_tunable(hyperparameters, init_params)

        # assert
        expected = {
            'this_is_not_conditional': {
                'type': 'int',
                'default': 1,
                'range': [1, 10]
            }
        }
        assert tunable == expected