From bbd5bf511b380bb8fea82bc3746261696e35fcfb Mon Sep 17 00:00:00 2001 From: Lopa10ko Date: Thu, 16 Jan 2025 19:38:55 +0300 Subject: [PATCH] feat: add anomaly detection --- .../ts_anomaly_detection_example.py | 51 ++++++++++++------- fedot_ind/tools/loader.py | 2 +- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/examples/automl_example/time_series/ts_anomaly_detection/ts_anomaly_detection_example.py b/examples/automl_example/time_series/ts_anomaly_detection/ts_anomaly_detection_example.py index 7a3b37a0e..79ed775ce 100644 --- a/examples/automl_example/time_series/ts_anomaly_detection/ts_anomaly_detection_example.py +++ b/examples/automl_example/time_series/ts_anomaly_detection/ts_anomaly_detection_example.py @@ -1,23 +1,36 @@ from fedot_ind.core.architecture.pipelines.abstract_pipeline import ApiTemplate +from fedot_ind.core.repository.config_repository import DEFAULT_COMPUTE_CONFIG + +DATASET_NAME = {'benchmark': 'valve1', + 'dataset': '1'} +METRIC_NAMES = ('nab', 'accuracy') + +COMPUTE_CONFIG = DEFAULT_COMPUTE_CONFIG +AUTOML_CONFIG = {'task': 'classification', + 'use_automl': True, + 'optimisation_strategy': {'optimisation_strategy': {'mutation_agent': 'bandit', + 'mutation_strategy': 'growth_mutation_strategy'}, + 'optimisation_agent': 'Industrial'}} +AUTOML_LEARNING_STRATEGY = dict(timeout=1, + n_jobs=2, + pop_size=10, + logging_level=0) + +LEARNING_CONFIG = {'learning_strategy': 'from_scratch', + 'learning_strategy_params': AUTOML_LEARNING_STRATEGY, + 'optimisation_loss': {'quality_loss': 'accuracy'}} + +INDUSTRIAL_CONFIG = {'problem': 'anomaly_detection', + 'strategy_params': {'detection_window': 10, + 'data_type': 'time_series'}} + +API_CONFIG = {'industrial_config': INDUSTRIAL_CONFIG, + 'automl_config': AUTOML_CONFIG, + 'learning_config': LEARNING_CONFIG, + 'compute_config': COMPUTE_CONFIG} if __name__ == "__main__": - dataset_name = dict(benchmark='valve1', - dataset='1') - prediction_window = 10 - finetune = False - metric_names = ('nab', 'accuracy') - api_config = dict( - problem='classification', - metric='accuracy', - timeout=1, - pop_size=10, - industrial_strategy='anomaly_detection', - industrial_task_params={ - 'detection_window': prediction_window, - 'data_type': 'time_series'}, - with_tuning=False, - n_jobs=2, - logging_level=20) - result_dict = ApiTemplate(api_config=api_config, - metric_list=metric_names).eval(dataset=dataset_name, finetune=finetune) + result_dict = ApiTemplate(api_config=API_CONFIG, + metric_list=METRIC_NAMES).eval(dataset=DATASET_NAME, + finetune=False) print(result_dict['metrics']) diff --git a/fedot_ind/tools/loader.py b/fedot_ind/tools/loader.py index e193c8703..dc530db5c 100644 --- a/fedot_ind/tools/loader.py +++ b/fedot_ind/tools/loader.py @@ -72,7 +72,7 @@ def local_m4_load(group: Optional[str] = None): @staticmethod def local_skab_load(directory: Union[Path, str] = 'other', group: Optional[str] = None): - path_to_result = EXAMPLES_DATA_PATH + f'/detection/data/{directory}' + path_to_result = EXAMPLES_DATA_PATH + f'/benchmark/detection/data/{directory}' df = pd.read_csv(Path(path_to_result, f'{group}.csv'), index_col='datetime', sep=';',