Skip to content

Commit

Permalink
Added None test case to AutoBase __str__ representation (#783)
Browse files Browse the repository at this point in the history
* Added null test case to AutoBase str rep test

* Updated no_param str representation test and cleaned up autobase __str__ private functions

* Updated test for core deps only

* Cleaned up test logic for checking items

* Removed extra import

* Updated changelog
  • Loading branch information
christopherbunn committed May 20, 2020
1 parent 5a5270d commit 2f26183
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 11 deletions.
1 change: 1 addition & 0 deletions docs/source/changelog.rst
Expand Up @@ -24,6 +24,7 @@ Changelog
* Delete codecov yml, use codecov.io's default :pr:`732`
* Added unit tests for fraud cost, lead scoring, and standard metric objectives :pr:`741`
* Update codecov client :pr:`782`
* Updated AutoBase __str__ test to include no parameters case :pr:`783`

.. warning::

Expand Down
20 changes: 9 additions & 11 deletions evalml/automl/auto_search_base.py
Expand Up @@ -15,7 +15,7 @@
from evalml.objectives import get_objective, get_objectives
from evalml.pipelines import get_pipelines
from evalml.pipelines.components import handle_component
from evalml.problem_types import ProblemTypes
from evalml.problem_types import ProblemTypes, handle_problem_types
from evalml.tuners import SKOptTuner
from evalml.utils import Logger, convert_to_seconds, get_random_state

Expand Down Expand Up @@ -98,11 +98,9 @@ def __init__(self, problem_type, tuner, cv, objective, max_pipelines, max_time,
self.plot = None

def __str__(self):
_list_separator = '\n\t'

def _print_list(in_attr):
return _list_separator + \
_list_separator.join(obj.name for obj in in_attr)
def _print_list(obj_list):
lines = ['\t{}'.format(o.name) for o in obj_list]
return '\n'.join(lines)

def _get_funct_name(function):
if callable(function):
Expand All @@ -111,20 +109,20 @@ def _get_funct_name(function):
return None

search_desc = (
f"{self.problem_type} Search\n\n"
f"{handle_problem_types(self.problem_type).name} Search\n\n"
f"Parameters: \n{'='*20}\n"
f"Objective: {self.objective.name}\n"
f"Objective: {get_objective(self.objective).name}\n"
f"Max Time: {self.max_time}\n"
f"Max Pipelines: {self.max_pipelines}\n"
f"Possible Pipelines: {_print_list(self.possible_pipelines)}\n"
f"Possible Pipelines: \n{_print_list(self.possible_pipelines or [])}\n"
f"Patience: {self.patience}\n"
f"Tolerance: {self.tolerance}\n"
f"Cross Validation: {self.cv}\n"
f"Tuner: {type(list(self.tuners.values())[0]).__name__}\n"
f"Tuner: {type(list(self.tuners.values())[0]).__name__ if len(self.tuners) else ''}\n"
f"Detect Label Leakage: {self.detect_label_leakage}\n"
f"Start Iteration Callback: {_get_funct_name(self.start_iteration_callback)}\n"
f"Add Result Callback: {_get_funct_name(self.add_result_callback)}\n"
f"Additional Objectives: {_print_list(self.additional_objectives)}\n"
f"Additional Objectives: {_print_list(self.additional_objectives or [])}\n"
f"Random State: {self.random_state}\n"
f"n_jobs: {self.n_jobs}\n"
f"Verbose: {self.verbose}\n"
Expand Down
43 changes: 43 additions & 0 deletions evalml/tests/automl_tests/test_autobase.py
Expand Up @@ -150,6 +150,7 @@ def _dummy_callback(param1, param2):
'Verbose': search_params['verbose'],
'Optimize Thresholds': search_params['optimize_thresholds']
}

automl = AutoClassificationSearch(**search_params)
str_rep = str(automl)

Expand All @@ -166,3 +167,45 @@ def _dummy_callback(param1, param2):
str_rep = str(automl)
assert "Search Results:" in str_rep
assert str(automl.rankings.drop(['parameters'], axis='columns')) in str_rep


def test_automl_str_no_param_search():
automl = AutoClassificationSearch()

param_str_reps = {
'Objective': 'Log Loss Binary',
'Max Time': 'None',
'Max Pipelines': 'None',
'Possible Pipelines': [
'Logistic Regression Binary Pipeline',
'Random Forest Binary Classification Pipeline'],
'Patience': 'None',
'Tolerance': '0.0',
'Cross Validation': 'StratifiedKFold(n_splits=3, random_state=0, shuffle=True)',
'Tuner': 'SKOptTuner',
'Detect Label Leakage': 'True',
'Additional Objectives': [
'Accuracy Binary',
'Balanced Accuracy Binary',
'F1',
'Precision',
'Recall',
'AUC',
'MCC Binary'],
'Start Iteration Callback': 'None',
'Add Result Callback': 'None',
'Random State': 'RandomState(MT19937)',
'n_jobs': '-1',
'Verbose': 'True',
'Optimize Thresholds': 'False'
}

str_rep = str(automl)

for param, value in param_str_reps.items():
assert f"{param}" in str_rep
if isinstance(value, list):
value = "\n".join(["\t{}".format(item) for item in value])
assert value in str_rep
assert "Possible Pipelines" in str_rep
assert "Search Results" not in str_rep

0 comments on commit 2f26183

Please sign in to comment.