Skip to content

Commit

Permalink
Fix default tuning params (#1175)
Browse files Browse the repository at this point in the history
Return default value with_tuning=True
  • Loading branch information
valer1435 authored Sep 28, 2023
1 parent 2ecbc7e commit a2cabc8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fedot/api/api_utils/api_params_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def default_params_for_task(task_type: TaskTypesEnum) -> dict:
cache_dir=default_fedot_data_dir(),
keep_history=True,
history_dir=default_fedot_data_dir(),
with_tuning=False
with_tuning=True
)
return default_param_values_dict

Expand Down
2 changes: 1 addition & 1 deletion fedot/api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Fedot:
genetic_scheme (str): name of the genetic scheme. Defaults to ``steady_state``.
with_tuning (bool): flag for tuning hyperparameters of the final evolved :class:`Pipeline`.
Defaults to ``False``.
Defaults to ``True``.
preset (str): name of the preset for model building (e.g. ``'best_quality'``, ``'fast_train'``, ``'gpu'``).
Default value is ``'auto'``.
Expand Down
26 changes: 16 additions & 10 deletions test/integration/api/test_main_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from test.unit.tasks.test_regression import get_synthetic_regression_data

TESTS_MAIN_API_DEFAULT_PARAMS = {
'timeout': 0.1,
'timeout': 0.5,
'preset': 'fast_train',
'max_depth': 1,
'max_arity': 2,
Expand Down Expand Up @@ -137,30 +137,36 @@ def data_with_binary_features_and_categorical_target():
"""
task = Task(TaskTypesEnum.classification)
features = np.array([['red', 'blue'],
['red', 'blue'],
['red', 'blue'],
[np.nan, 'blue'],
['green', 'blue'],
['green', 'orange']])
target = np.array(['red-blue', 'red-blue', 'green-blue', 'green-orange'])
train_input = InputData(idx=[0, 1, 2, 3], features=features, target=target,
['green', 'orange'],
['red', 'orange']])
target = np.array(['red-blue', 'red-blue', 'red-blue', 'red-blue', 'green-blue', 'green-orange', 'red-orange'])
train_input = InputData(idx=[0, 1, 2, 3, 4, 5, 6], features=features, target=target,
task=task, data_type=DataTypesEnum.table,
supplementary_data=SupplementaryData())

return train_input


@pytest.mark.parametrize('task_type, predefined_model, metric_name', [
('classification', 'dt', 'f1'),
('regression', 'dtreg', 'rmse'),
@pytest.mark.parametrize('task_type, metric_name', [
('classification', 'f1'),
('regression', 'rmse'),
])
def test_api_predict_correct(task_type, predefined_model, metric_name):
def test_api_predict_correct(task_type, metric_name):
train_data, test_data, _ = get_dataset(task_type)
model = Fedot(problem=task_type, **TESTS_MAIN_API_DEFAULT_PARAMS)
fedot_model = model.fit(features=train_data, predefined_model=predefined_model)
fedot_model = model.fit(features=train_data)
prediction = model.predict(features=test_data)
metric = model.get_metrics(metric_names=metric_name, rounding_order=5)
assert isinstance(fedot_model, Pipeline)
assert len(prediction) == len(test_data.target)
assert all(value > 0 for value in metric.values())
assert all(value >= 0 for value in metric.values())
# composing and tuning was applied
assert model.history is not None
assert model.history.tuning_result is not None
assert is_predict_ignores_target(model.predict, train_data, 'features')


Expand Down
2 changes: 1 addition & 1 deletion test/unit/api/test_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_auto_preset_converted_correctly():

simple_init_assumption = Pipeline(PipelineNode('logit'))
fedot_model = Fedot(problem='classification', preset='auto', timeout=tiny_timeout_value,
initial_assumption=simple_init_assumption, pop_size=large_pop_size)
initial_assumption=simple_init_assumption, pop_size=large_pop_size, with_tuning=False)
# API must return initial assumption without composing and tuning (due to population size is too large)
fedot_model.fit(data)
assert fedot_model.params.get('preset') == FAST_TRAIN_PRESET_NAME
Expand Down

0 comments on commit a2cabc8

Please sign in to comment.