コード例 #1
0
def test_train_and_score_pipelines_error(mock_fit, mock_score,
                                         dummy_binary_pipeline_class,
                                         X_y_binary, caplog):
    X, y = X_y_binary
    mock_score.side_effect = Exception('yeet')
    automl = AutoMLSearch(X_train=X,
                          y_train=y,
                          problem_type='binary',
                          max_time=1,
                          max_batches=1,
                          allowed_pipelines=[dummy_binary_pipeline_class({})])
    pipeline = dummy_binary_pipeline_class({})

    job_log = JobLogger()
    result = evaluate_pipeline(pipeline,
                               automl,
                               automl.X_train,
                               automl.y_train,
                               logger=job_log)
    evaluation_result, job_log = result.get("scores"), result.get("logger")
    logger = get_logger(__file__)
    job_log.write_to_logger(logger)

    assert mock_fit.call_count == automl.data_splitter.get_n_splits()
    assert mock_score.call_count == automl.data_splitter.get_n_splits()
    assert evaluation_result.get('training_time') is not None
    assert np.isnan(evaluation_result.get('cv_score_mean'))
    pd.testing.assert_series_equal(evaluation_result.get('cv_scores'),
                                   pd.Series([np.nan] * 3))
    for i in range(automl.data_splitter.get_n_splits()):
        assert np.isnan(evaluation_result['cv_data'][i]['all_objective_scores']
                        ['Log Loss Binary'])
    assert 'yeet' in caplog.text
コード例 #2
0
def test_job_logger_warning_and_error_messages(caplog):
    job_log = JobLogger()
    job_log.warning("This is a warning!")
    job_log.error("This is an error!")
    logger = get_logger(__file__)
    job_log.write_to_logger(logger)

    assert "This is a warning!" in caplog.text
    assert "This is an error!" in caplog.text
コード例 #3
0
import warnings
from collections import namedtuple
from functools import reduce

import numpy as np
import pandas as pd
import woodwork as ww
from sklearn.utils import check_random_state

from evalml.exceptions import (
    EnsembleMissingPipelinesError,
    MissingComponentError
)
from evalml.utils import get_logger

logger = get_logger(__file__)


def import_or_raise(library, error_msg=None, warning=False):
    """Attempts to import the requested library by name.
    If the import fails, raises an ImportError or warning.

    Arguments:
        library (str): the name of the library
        error_msg (str): error message to return if the import fails
        warning (bool): if True, import_or_raise gives a warning instead of ImportError. Defaults to False.
    """
    try:
        return importlib.import_module(library)
    except ImportError:
        if error_msg is None: