Example #1
0
def test_JobConfig():

    dfX, y, auto_ml_config = get_automl_config()

    job_config = JobConfig()
    job_config.guess_cv(auto_ml_config)

    assert job_config.cv is not None

    job_config.guess_scoring(auto_ml_config)
    assert isinstance(job_config.scoring, list)
Example #2
0
    def initialize(self):
        """ method to initialize auto_ml_config and job_config """

        ##################################
        ### ** load data and target ** ###
        ##################################
        if self.dfX is None or self.y is None:
            temp = self.loader()
            if len(temp) == 2:
                self.dfX, self.y = temp
                self.groups = None
            else:
                self.dfX, self.y, self.groups = temp

        ###########################################
        ### ** create database configuration ** ###
        ###########################################
        if self.auto_ml_config is None:
            self.auto_ml_config = AutoMlConfig(dfX=self.dfX,
                                               y=self.y,
                                               groups=self.groups,
                                               name=self.name)
            self.auto_ml_config.guess_everything()

        #####################################
        ### ** create job configuation ** ###
        #####################################
        if self.job_config is None:
            self.job_config = JobConfig()
            self.job_config.guess_cv(auto_ml_config=self.auto_ml_config,
                                     n_splits=10)
            self.job_config.guess_scoring(auto_ml_config=self.auto_ml_config)

        ###################################
        ### ** create data persister ** ###
        ###################################
        if self.data_persister is None:
            self.data_persister = FolderDataPersister(
                base_folder=self.base_folder)

        #################################
        ### ** apply custom config ** ###
        #################################
        if self.set_configs is not None:
            self.set_configs(self)
Example #3
0
def test_JobConfig(num_only):

    dfX, y, auto_ml_config = get_automl_config(num_only)

    job_config = JobConfig()
    job_config.guess_cv(auto_ml_config)

    assert job_config.cv is not None
    assert hasattr(job_config.cv, "split")

    job_config.guess_scoring(auto_ml_config)
    assert isinstance(job_config.scoring, list)

    assert hasattr(job_config, "allow_approx_cv")
    assert hasattr(job_config, "start_with_default")
    assert hasattr(job_config, "do_blocks_search")

    assert isinstance(job_config.allow_approx_cv, bool)
    assert isinstance(job_config.start_with_default, bool)
    assert isinstance(job_config.do_blocks_search, bool)

    with pytest.raises(ValueError):
        job_config.cv = "this is not a cv"
Example #4
0
def test_JobConfig_additional_scoring_function():
    job_config = JobConfig()

    assert job_config.additional_scoring_function is None

    def f(x):
        return x + 1

    job_config.additional_scoring_function = f
    assert job_config.additional_scoring_function is not None
    assert job_config.additional_scoring_function(1) == 2

    with pytest.raises(TypeError):
        job_config.additional_scoring_function = 10  # no a function

    def f(x):
        return x + 1

    job_config.additional_scoring_function = f
    assert job_config.additional_scoring_function is not None
    assert job_config.additional_scoring_function(1) == 2

    with pytest.raises(TypeError):
        job_config.additional_scoring_function = 10  # no a function
Example #5
0
def test_create_everything_sequentially(num_only, tmpdir):

    # DataPersister
    data_persister = FolderDataPersister(base_folder=tmpdir)

    # Data
    dfX, y = loader(num_only)

    # Auto Ml Config
    auto_ml_config = AutoMlConfig(dfX, y)
    auto_ml_config.guess_everything()
    assert auto_ml_config

    # Job Config
    job_config = JobConfig()
    job_config.guess_scoring(auto_ml_config)
    job_config.guess_cv(auto_ml_config)
    assert job_config

    # Result Reader
    result_reader = AutoMlResultReader(data_persister)
    assert result_reader  # just verify the object was created

    # Auto ml guider
    auto_ml_guider = AutoMlModelGuider(result_reader=result_reader,
                                       job_config=job_config,
                                       metric_transformation="default",
                                       avg_metric=True)
    assert auto_ml_guider

    # Job Controller
    job_controller = MlJobManager(
        auto_ml_config=auto_ml_config,
        job_config=job_config,
        auto_ml_guider=auto_ml_guider,
        data_persister=data_persister,
        seed=None,
    )

    assert job_controller

    # Job Runner
    job_runner = MlJobRunner(
        dfX=dfX,
        y=y,
        groups=None,
        auto_ml_config=auto_ml_config,
        job_config=job_config,
        data_persister=data_persister,
        seed=None,
    )

    assert job_runner

    ### Do one iteration of the job_controller

    for i, (temp_job_id,
            temp_job_param) in enumerate(job_controller.iterate()):

        if i > 0:
            break  # I need to complete a loop, so I need the break to be AFTER second yield

        job_id = temp_job_id
        job_param = temp_job_param
        assert isinstance(job_id, str)
        assert isinstance(job_param, dict)

    ### retriveve job by worker
    for worker_job_id, worker_job_param in job_runner.iterate():
        break

    assert isinstance(worker_job_id, str)
    assert isinstance(worker_job_param, dict)

    assert worker_job_id == job_id
    assert worker_job_param == job_param