-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'industrial_release_0.5' of https://github.com/aimclub/F…
…edot.Industrial into industrial_release_0.5
- Loading branch information
Showing
5 changed files
with
87 additions
and
92 deletions.
There are no files selected for viewing
54 changes: 25 additions & 29 deletions
54
examples/automl_example/custom_strategy/specific_strategy/probability_calibration_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,38 @@ | ||
import numpy as np | ||
|
||
from examples.example_utils import create_feature_generator_strategy | ||
from fedot_ind.core.architecture.pipelines.abstract_pipeline import ApiTemplate | ||
from fedot_ind.core.repository.config_repository import DEFAULT_COMPUTE_CONFIG, \ | ||
DEFAULT_AUTOML_LEARNING_CONFIG | ||
|
||
INDUSTRIAL_PARAMS = {'data_type': 'tensor', | ||
'learning_strategy': 'ts2tabular' | ||
} | ||
|
||
# DEFINE ALL CONFIG FOR API | ||
AUTOML_LEARNING_STRATEGY = DEFAULT_AUTOML_LEARNING_CONFIG | ||
COMPUTE_CONFIG = DEFAULT_COMPUTE_CONFIG | ||
AUTOML_CONFIG = {'task': 'classification'} | ||
LEARNING_CONFIG = {'learning_strategy': 'from_scratch', | ||
'learning_strategy_params': AUTOML_LEARNING_STRATEGY, | ||
'optimisation_loss': {'quality_loss': 'f1'}} | ||
INDUSTRIAL_CONFIG = {'problem': 'classification', | ||
'strategy': 'tabular', | ||
'strategy_params': INDUSTRIAL_PARAMS | ||
} | ||
API_CONFIG = {'industrial_config': INDUSTRIAL_CONFIG, | ||
'automl_config': AUTOML_CONFIG, | ||
'learning_config': LEARNING_CONFIG, | ||
'compute_config': COMPUTE_CONFIG} | ||
|
||
if __name__ == "__main__": | ||
dataset_name = 'Libras' | ||
finetune = False | ||
api_config = dict(problem='classification', | ||
metric='f1', | ||
timeout=0.1, | ||
n_jobs=2, | ||
logging_level=20) | ||
DATASET_NAME = 'Libras' | ||
|
||
feature_generator, sampling_dict = create_feature_generator_strategy() | ||
DEFAULT_AUTOML_LEARNING_CONFIG['timeout'] = 0.1 | ||
|
||
AUTOML_CONFIG = {'task': 'classification'} | ||
LEARNING_CONFIG = {'learning_strategy': 'from_scratch', | ||
'learning_strategy_params': DEFAULT_AUTOML_LEARNING_CONFIG, | ||
'optimisation_loss': {'quality_loss': 'f1'}} | ||
INDUSTRIAL_CONFIG = {'problem': 'classification', | ||
'strategy': 'tabular', | ||
'strategy_params': {'feature_generator': feature_generator, | ||
'data_type': 'tensor', | ||
'learning_strategy': 'ts2tabular', | ||
'sampling_strategy': sampling_dict}} | ||
|
||
API_CONFIG = {'industrial_config': INDUSTRIAL_CONFIG, | ||
'automl_config': AUTOML_CONFIG, | ||
'learning_config': LEARNING_CONFIG, | ||
'compute_config': DEFAULT_COMPUTE_CONFIG} | ||
|
||
api_client = ApiTemplate(api_config=API_CONFIG, | ||
metric_list=('f1', 'accuracy')) | ||
result_dict = api_client.eval(dataset=dataset_name, finetune=finetune) | ||
uncalibrated_labels, uncalibrated_probs = result_dict['industrial_model'].predicted_labels, \ | ||
result_dict['industrial_model'].predicted_probs | ||
result_dict = api_client.eval(dataset=DATASET_NAME, finetune=False) | ||
uncalibrated_labels, uncalibrated_probs = result_dict['industrial_model'].manager.predicted_labels, \ | ||
result_dict['industrial_model'].manager.predicted_probs | ||
calibrated_probs = result_dict['industrial_model'].predict_proba(predict_data=api_client.test_data, | ||
calibrate_probs=True) | ||
calibrated_labels = np.argmax(calibrated_probs, axis=1) + np.min(uncalibrated_labels) |
67 changes: 30 additions & 37 deletions
67
examples/automl_example/time_series/ts_forecasting/forecasting_strategy_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,43 @@ | ||
import pickle | ||
|
||
from fedot_ind.core.architecture.pipelines.abstract_pipeline import ApiTemplate | ||
from fedot_ind.core.repository.config_repository import DEFAULT_COMPUTE_CONFIG, DEFAULT_TSF_AUTOML_CONFIG, \ | ||
DEFAULT_AUTOML_LEARNING_CONFIG | ||
from fedot_ind.core.repository.constanst_repository import M4_FORECASTING_BENCH | ||
|
||
finetune = False | ||
|
||
|
||
def forecasting_loop(dataset_dict, api_config): | ||
metric_names = ('rmse', 'smape') | ||
result_dict = ApiTemplate(api_config=api_config, | ||
metric_list=metric_names).eval(dataset=dataset_dict, | ||
finetune=finetune) | ||
|
||
return result_dict | ||
|
||
|
||
def evaluate_for_M4(type: str = 'M'): | ||
dataset_list = [data for data in M4_FORECASTING_BENCH if data.__contains__(type)] | ||
return dataset_list | ||
|
||
|
||
if __name__ == "__main__": | ||
bench = 'M4' | ||
group = 'M' | ||
forecast_params = {'forecast_length': 8} | ||
horizon = forecast_params['forecast_length'] | ||
dataset_list = evaluate_for_M4(group) | ||
api_config = dict( | ||
problem='ts_forecasting', | ||
metric='rmse', | ||
timeout=5, | ||
with_tuning=False, | ||
industrial_strategy='forecasting_assumptions', | ||
industrial_strategy_params={ | ||
'industrial_task': 'ts_forecasting', | ||
'data_type': 'time_series'}, | ||
task_params=forecast_params, | ||
logging_level=50) | ||
METRIC_NAMES = ('rmse', 'smape') | ||
HORIZON = 8 | ||
TASK_PARAMS = {'forecast_length': HORIZON} | ||
BENCH = 'M4' | ||
GROUP = 'M' | ||
|
||
DATASET_NAMES = [data for data in M4_FORECASTING_BENCH if data.__contains__(GROUP)] | ||
|
||
DEFAULT_AUTOML_LEARNING_CONFIG['timeout'] = 5 | ||
|
||
API_CONFIG = {'industrial_config': {'problem': 'ts_forecasting', | ||
'data_type': 'time_series', | ||
'learning_strategy': 'forecasting_assumptions', | ||
'task_params': TASK_PARAMS}, | ||
'automl_config': {**DEFAULT_TSF_AUTOML_CONFIG, | ||
'task_params': TASK_PARAMS}, | ||
'learning_config': {'learning_strategy': 'from_scratch', | ||
'learning_strategy_params': DEFAULT_AUTOML_LEARNING_CONFIG, | ||
'optimisation_loss': {'quality_loss': 'rmse'}}, | ||
'compute_config': DEFAULT_COMPUTE_CONFIG} | ||
|
||
result_dict = {} | ||
|
||
for dataset_name in dataset_list: | ||
dataset_dict = {'benchmark': bench, | ||
for dataset_name in DATASET_NAMES: | ||
dataset_dict = {'benchmark': BENCH, | ||
'dataset': dataset_name, | ||
'task_params': forecast_params} | ||
result_dict = forecasting_loop(dataset_dict, api_config) | ||
'task_params': TASK_PARAMS} | ||
result_dict = ApiTemplate(api_config=API_CONFIG, | ||
metric_list=METRIC_NAMES).eval(dataset=dataset_dict, | ||
finetune=False) | ||
result_dict.update({dataset_name: result_dict}) | ||
|
||
with open(f'{bench}_{group}_forecast_length_{horizon}.pkl', 'wb') as f: | ||
with open(f'{BENCH}_{GROUP}_forecast_length_{HORIZON}.pkl', 'wb') as f: | ||
pickle.dump(result_dict, f) |
54 changes: 29 additions & 25 deletions
54
examples/automl_example/time_series/ts_forecasting/ts_forecasting_exogen.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,39 @@ | ||
import numpy as np | ||
import pandas as pd | ||
|
||
from examples.example_utils import load_monash_dataset | ||
from fedot_ind.api.main import FedotIndustrial | ||
from fedot_ind.tools.serialisation.path_lib import PROJECT_PATH | ||
from fedot_ind.core.repository.config_repository import DEFAULT_COMPUTE_CONFIG, DEFAULT_TSF_AUTOML_CONFIG | ||
|
||
if __name__ == "__main__": | ||
dataset_name = PROJECT_PATH + \ | ||
'/examples/data/forecasting\\monash_benchmark\\MonashBitcoin_30.csv' | ||
horizon = 60 | ||
metric_names = ('smape', 'rmse', 'median_absolute_error') | ||
HORIZON = 60 | ||
METRIC_NAMES = ('smape', 'rmse', 'median_absolute_error') | ||
|
||
train_data = pd.read_csv(dataset_name) | ||
variables = train_data['label'].unique().tolist() | ||
exog_var = ['send_usd', 'market_cap', | ||
'median_transaction_value', 'google_trends'] | ||
exog_ts = np.vstack( | ||
[train_data[train_data['label'] == var]['value'].values for var in exog_var]) | ||
train_data = load_monash_dataset('bitcoin') | ||
exog_var = ['send_usd', 'market_cap', 'median_transaction_value', 'google_trends'] | ||
exog_ts = np.vstack([train_data[column].values for column in exog_var]) | ||
exog_ts = exog_ts[0, :] | ||
ts = train_data[train_data['label'] == 'price']['value'].values | ||
target = ts[-horizon:].flatten() | ||
ts = train_data['price'].values | ||
target = ts[-HORIZON:].flatten() | ||
input_data = (ts, target) | ||
|
||
api_config = dict(problem='ts_forecasting', | ||
metric='rmse', | ||
timeout=15, | ||
with_tuning=False, | ||
pop_size=10, | ||
industrial_strategy_params={'exog_variable': exog_ts}, | ||
task_params={'forecast_length': horizon}, | ||
industrial_strategy='forecasting_exogenous', | ||
n_jobs=2, | ||
logging_level=30) | ||
industrial = FedotIndustrial(**api_config) | ||
TASK_PARAMS = {'forecast_length': HORIZON} | ||
AUTOML_LEARNING_STRATEGY = dict(timeout=3, | ||
with_tuning=False, | ||
n_jobs=2, | ||
pop_size=10, | ||
logging_level=30) | ||
|
||
API_CONFIG = {'industrial_config': {'problem': 'ts_forecasting', | ||
'task_params': TASK_PARAMS, | ||
'strategy': 'forecasting_exogenous', | ||
'strategy_params': {'exog_variable': exog_ts, | ||
'data_type': 'time_series'}}, | ||
'automl_config': {'task_params': TASK_PARAMS, | ||
**DEFAULT_TSF_AUTOML_CONFIG}, | ||
'learning_config': {'learning_strategy': 'from_scratch', | ||
'learning_strategy_params': AUTOML_LEARNING_STRATEGY, | ||
'optimisation_loss': {'quality_loss': 'rmse'}}, | ||
'compute_config': DEFAULT_COMPUTE_CONFIG} | ||
|
||
industrial = FedotIndustrial(**API_CONFIG) | ||
industrial.fit(input_data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters