Ejemplo n.º 1
0
    def make_from_setup(self, setup, data=None):

        self.setup = defaults.add_defaults_to_setup(setup)

        self.features = list(self.setup['features'].keys())
        self.regressors = list(self.setup['regressors'].keys())
        self.classifiers = list(self.setup['classifiers'].keys())

        self._prepare_data(data=data)
        self._make_preprocessors_from_setup()
        self._make_model_from_setup()
Ejemplo n.º 2
0
    def test_set_default_scaler_encoder(self):

        setup = {
            'default_scaler': 'MinMaxScaler',
            'default_encoder': 'OrdinalEncoder',
            'features': ['M1', 'qinit', 'Pinit', 'FeHinit'],
            'regressors': ['Pfinal', 'qfinal'],
            'classifiers': ['product', 'binary_type'],
        }

        setup_new = defaults.add_defaults_to_setup(setup)

        assert setup_new['features']['M1']['processor'] == 'MinMaxScaler'
        assert setup_new['classifiers']['product'][
            'processor'] == 'OrdinalEncoder'
Ejemplo n.º 3
0
    def test_add_defaults_to_setup(self):

        setup = {
            'features': ['M1', 'qinit', 'Pinit', 'FeHinit'],
            'regressors': ['Pfinal', 'qfinal'],
            'classifiers': ['product', 'binary_type'],
        }

        setup_new = defaults.add_defaults_to_setup(setup)

        assert 'model' in setup_new

        assert 'random_state' in setup_new
        assert 'train_test_split' in setup_new

        assert 'optimizer' in setup_new
        assert 'optimizer_kwargs' in setup_new
Ejemplo n.º 4
0
    def test_add_loss_defaults_to_setup(self):

        #-- case where features, regressors and classifiers are lists
        setup = {
            'features': ['M1', 'qinit', 'Pinit', 'FeHinit'],
            'regressors': ['Pfinal', 'qfinal'],
            'classifiers': ['product', 'binary_type'],
        }

        setup_new = defaults.add_defaults_to_setup(setup)

        assert 'loss' in setup_new['regressors']['Pfinal']
        assert setup_new['regressors']['Pfinal'][
            'loss'] == defaults.default_regressor_loss

        assert 'loss' in setup_new['classifiers']['product']
        assert setup_new['classifiers']['product'][
            'loss'] == defaults.default_classifier_loss

        #-- case where features, regressors and classifiers are dictionaries

        setup = {
            'features': {
                'M1': {
                    'processor': 'StandardScaler'
                },
                'qinit': {
                    'processor': 'RobustScaler'
                },
                'Pinit': {
                    'processor': 'MinMaxScaler'
                },
                'FeHinit': {
                    'processor': 'MaxAbsScaler'
                },
            },
            'regressors': {
                'Pfinal': {
                    'processor': 'StandardScaler',
                    'loss': 'mafe'
                },
                'qfinal': {
                    'processor': 'RobustScaler'
                },
            },
            'classifiers': {
                'product': None,
            },
        }

        setup_new = defaults.add_defaults_to_setup(setup)

        assert 'loss' in setup_new['regressors']['Pfinal']
        assert setup_new['regressors']['Pfinal']['loss'] == 'mafe'

        assert setup_new['regressors']['qfinal'][
            'loss'] == defaults.default_regressor_loss

        assert 'loss' in setup_new['classifiers']['product']
        assert setup_new['classifiers']['product'][
            'loss'] == defaults.default_classifier_loss
Ejemplo n.º 5
0
    def test_add_processor_defaults_to_setup(self):

        #-- case where features, regressors and classifiers are lists
        setup = {
            'features': ['M1', 'qinit', 'Pinit', 'FeHinit'],
            'regressors': ['Pfinal', 'qfinal'],
            'classifiers': ['product', 'binary_type'],
        }

        setup_new = defaults.add_defaults_to_setup(setup)

        assert 'processor' in setup_new['features']['M1']
        assert setup_new['features']['M1'][
            'processor'] == defaults.default_scaler

        assert 'processor' in setup_new['regressors']['Pfinal']
        assert setup_new['regressors']['Pfinal']['processor'] is None

        assert 'processor' in setup_new['classifiers']['product']
        assert setup_new['classifiers']['product'][
            'processor'] == defaults.default_encoder

        #-- case where features, regressors and classifiers are dictionaries

        setup = {
            'features': {
                'M1': {
                    'processor': 'StandardScaler'
                },
                'qinit': {
                    'processor': 'RobustScaler'
                },
                'Pinit': {
                    'processor': 'MinMaxScaler'
                },
                'FeHinit': {
                    'processor': 'MaxAbsScaler'
                },
            },
            'regressors': ['Pfinal', 'qfinal'],
            'classifiers': {
                'binary_type': {
                    'processor': None
                },
                'product': None,
            },
        }

        setup_new = defaults.add_defaults_to_setup(setup)

        for key in setup['features'].keys():
            assert setup_new['features'][key]['processor'] == setup[
                'features'][key]['processor']

        for key in setup['regressors']:
            assert setup_new['regressors'][key]['processor'] is None

        assert setup_new['classifiers']['binary_type']['processor'] is None

        assert setup_new['classifiers']['product'][
            'processor'] == 'OneHotEncoder'