Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bring back cgru integration tests #1313

Merged
merged 8 commits into from
Jul 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
`sgdr`,Stochastic Gradient Descent regressor,Regression
`svr`,Linear Support Vector regressor,Regression
`treg`,Extra Trees regressor,Regression
`xgbreg`,Extreme Gradient Boosting regressor,Regression
`xgboostreg`,Extreme Gradient Boosting regressor,Regression
`bernb`,Naive Bayes classifier (multivariate Bernoulli),Classification
`catboost`,Catboost classifier,Classification
`cnn`,Convolutional Neural Network,Classification
Expand Down Expand Up @@ -190,7 +190,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
`sgdr`,`sklearn.linear_model.SGDRegressor`,`fast_train` `ts`
`svr`,`sklearn.svm.LinearSVR`,
`treg`,`sklearn.ensemble.ExtraTreesRegressor`,`*tree`
`xgbreg`,`xgboost.XGBRegressor`,`*tree`
`xgboostreg`,`FEDOT model`,`*tree`
aPovidlo marked this conversation as resolved.
Show resolved Hide resolved
`bernb`,`sklearn.naive_bayes.BernoulliNB`,`fast_train`
`catboost`,`catboost.CatBoostClassifier`,`*tree`
`cnn`,`FEDOT model`,
Expand All @@ -204,7 +204,7 @@ Apart from that there are other options whose names speak for themselves: ``'sta
`qda`,`sklearn.discriminant_analysis.QuadraticDiscriminantAnalysis`,`fast_train`
`rf`,`sklearn.ensemble.RandomForestClassifier`,`fast_train` `*tree`
`svc`,`sklearn.svm.SVC`,
`xgboost`,`xgboost.XGBClassifier`,`*tree`
`xgboost`,`FEDOT model`,`*tree`
aPovidlo marked this conversation as resolved.
Show resolved Hide resolved
`kmeans`,`sklearn.cluster.Kmeans`,`fast_train`
`ar`,`statsmodels.tsa.ar_model.AutoReg`,`fast_train` `ts`
`arima`,`statsmodels.tsa.arima.model.ARIMA`,`ts`
Expand Down
4 changes: 1 addition & 3 deletions test/integration/api/test_main_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,6 @@ def test_pandas_input_for_api():

train_features = pd.DataFrame(train_data.features)
train_target = pd.Series(train_data.target.reshape(-1))

test_features = pd.DataFrame(test_data.features)
test_target = pd.Series(test_data.target.reshape(-1))

# task selection, initialisation of the framework
Expand All @@ -177,7 +175,7 @@ def test_pandas_input_for_api():
baseline_model.fit(features=train_features, target=train_target, predefined_model='xgboost')

# evaluate the prediction with test data
prediction = baseline_model.predict(features=test_features)
prediction = baseline_model.predict(features=test_data)

assert len(prediction) == len(test_target)

Expand Down
79 changes: 38 additions & 41 deletions test/integration/models/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,56 +461,54 @@ def test_locf_forecast_correctly():
assert np.array_equal(predict_forecast.predict, np.array([[110, 120, 130, 110]]))


def test_models_does_not_fall_on_constant_data():
@pytest.mark.parametrize('operation', OperationTypesRepository('all')._repo, ids=lambda x: x.id)
aPovidlo marked this conversation as resolved.
Show resolved Hide resolved
def test_models_does_not_fall_on_constant_data(operation):
""" Run models on constant data """
# models that raise exception
to_skip = ['custom', 'arima', 'catboost', 'catboostreg', 'cgru',
'lda', 'fast_ica', 'decompose', 'class_decompose']
to_skip = {'custom', 'arima', 'catboost', 'catboostreg', 'cgru', 'lda', 'decompose', 'class_decompose'}
aPovidlo marked this conversation as resolved.
Show resolved Hide resolved
if operation.id in to_skip:
return

for operation in OperationTypesRepository('all')._repo:
if operation.id in to_skip:
continue
for task_type in operation.task_type:
for data_type in operation.input_types:
data = get_data_for_testing(task_type, data_type,
length=100, features_count=2,
random=False)
if data is not None:
for task_type in operation.task_type:
for data_type in operation.input_types:
data = get_data_for_testing(task_type, data_type,
length=100, features_count=2,
random=False)
if data is not None:
nodes_from = []
if task_type is TaskTypesEnum.ts_forecasting:
if 'non_lagged' not in operation.tags:
nodes_from = [PipelineNode('lagged')]
node = PipelineNode(operation.id, nodes_from=nodes_from)
pipeline = Pipeline(node)
pipeline.fit(data)
assert pipeline.predict(data) is not None


@pytest.mark.parametrize('operation', OperationTypesRepository('all')._repo, ids=lambda x: x.id)
def test_operations_are_serializable(operation):
to_skip = ['custom', 'decompose', 'class_decompose']
if operation.id in to_skip:
return

for task_type in operation.task_type:
for data_type in operation.input_types:
data = get_data_for_testing(task_type, data_type,
length=100, features_count=2,
random=True)
if data is not None:
try:
aPovidlo marked this conversation as resolved.
Show resolved Hide resolved
nodes_from = []
if task_type is TaskTypesEnum.ts_forecasting:
if 'non_lagged' not in operation.tags:
nodes_from = [PipelineNode('lagged')]
node = PipelineNode(operation.id, nodes_from=nodes_from)
pipeline = Pipeline(node)
pipeline.fit(data)
assert pipeline.predict(data) is not None


def test_operations_are_serializable():
to_skip = ['custom', 'decompose', 'class_decompose']

for operation in OperationTypesRepository('all')._repo:
if operation.id in to_skip:
continue
for task_type in operation.task_type:
for data_type in operation.input_types:
data = get_data_for_testing(task_type, data_type,
length=100, features_count=2,
random=True)
if data is not None:
try:
nodes_from = []
if task_type is TaskTypesEnum.ts_forecasting:
if 'non_lagged' not in operation.tags:
nodes_from = [PipelineNode('lagged')]
node = PipelineNode(operation.id, nodes_from=nodes_from)
pipeline = Pipeline(node)
pipeline.fit(data)
serialized = pickle.dumps(pipeline, pickle.HIGHEST_PROTOCOL)
assert isinstance(serialized, bytes)
except NotImplementedError:
pass
serialized = pickle.dumps(pipeline, pickle.HIGHEST_PROTOCOL)
assert isinstance(serialized, bytes)
except NotImplementedError:
pass


def test_operations_are_fast():
Expand All @@ -534,7 +532,7 @@ def test_operations_are_fast():
reference_time = tuple(map(min, zip(perfomance_values, reference_time)))

for operation in OperationTypesRepository('all')._repo:
if (operation.id not in to_skip and operation.presets and FAST_TRAIN_PRESET_NAME in operation.presets):
if operation.id not in to_skip and operation.presets and FAST_TRAIN_PRESET_NAME in operation.presets:
for _ in range(attempt):
perfomance_values = get_operation_perfomance(operation, data_lengths)
# if attempt is successful then stop
Expand All @@ -548,7 +546,6 @@ def test_all_operations_are_documented():
# All operations and presets should be listed in `docs/source/introduction/fedot_features/automation_features.rst`
to_skip = {'custom', 'data_source_img', 'data_source_text', 'data_source_table', 'data_source_ts', 'exog_ts'}
path_to_docs = fedot_project_root() / 'docs/source/introduction/fedot_features/automation_features.rst'
docs_lines = None

with open(path_to_docs, 'r') as docs_:
docs_lines = docs_.readlines()
Expand Down
27 changes: 8 additions & 19 deletions test/integration/real_applications/test_heavy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@
from fedot.core.pipelines.pipeline_builder import PipelineBuilder


@pytest.mark.skip(reason="Fails due to the https://github.com/aimclub/FEDOT/issues/1240")
aPovidlo marked this conversation as resolved.
Show resolved Hide resolved
def test_cgru_forecasting():
@pytest.mark.parametrize('pipeline', (
PipelineBuilder().add_node('lagged', params={'window_size': 200}).add_node('cgru').build(),
cgru_pipeline(),
), ids=str)
def test_cgru_forecasting(pipeline):
horizon = 5
window_size = 200
train_data, test_data = get_ts_data('salaries', horizon)

pipeline = PipelineBuilder().add_node('lagged', params={'window_size': window_size}).add_node('cgru').build()
pipeline.fit(train_data)
predicted = pipeline.predict(test_data).predict[0]

assert len(predicted) == horizon


@pytest.mark.skip(reason="Fails due to the https://github.com/aimclub/FEDOT/issues/1240")
def test_cgru_in_pipeline():
horizon = 5
train_data, test_data = train_data, test_data = get_ts_data('salaries', horizon)

pipeline = cgru_pipeline()
train_data, test_data, _ = get_ts_data('salaries', horizon)
pipeline.fit(train_data)
predicted = pipeline.predict(test_data).predict[0]
predicted = pipeline.predict(test_data).predict

assert predicted is not None
assert len(predicted) == horizon
Loading