From 6782206b7a8b75c6a4e0e44a7bb6e00e756b3a70 Mon Sep 17 00:00:00 2001 From: "alessandro.romualdi" Date: Wed, 24 Nov 2021 11:51:52 +0100 Subject: [PATCH 1/2] add integration test for pyMUVR feature selection --- don't change below this line --- {id} <#DTT#> --- tests/test_feature_selector_integration.py | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/test_feature_selector_integration.py diff --git a/tests/test_feature_selector_integration.py b/tests/test_feature_selector_integration.py new file mode 100644 index 0000000..af18514 --- /dev/null +++ b/tests/test_feature_selector_integration.py @@ -0,0 +1,41 @@ +import pytest + +from sklearn.datasets import make_classification +from sklearn.svm import SVC + +from py_muvr.feature_selector import FeatureSelector + + +@pytest.fixture() +def artificial_data(): + return make_classification( + n_features=10, + n_informative=2, + n_redundant=2, + n_samples=100, + n_classes=2, + random_state=0, + shuffle=False, + ) + + +@pytest.mark.parametrize( + "estimator", ["RFC", "XGBC", "PLSC", SVC(kernel="linear", random_state=1)] +) +def test_feature_selection_artificial_data_plsc(artificial_data, estimator): + + fs = FeatureSelector( + n_outer=5, + n_repetitions=5, + random_state=0, + estimator=estimator, + metric="accuracy", + features_dropout_rate=0.05, + ) + + X, y = artificial_data + fitted_fs = fs.fit(X, y) + selected_features = fitted_fs._selected_features + + assert selected_features["min"] == [0, 1] # first two features + assert selected_features["max"] == [0, 3] # thirds and fourth feature From 53677fb2d78bea11998d63a02e2d9b4835c37193 Mon Sep 17 00:00:00 2001 From: "alessandro.romualdi" Date: Wed, 24 Nov 2021 11:57:13 +0100 Subject: [PATCH 2/2] use set comparison in test --- don't change below this line --- {id} <#DTT#> --- tests/test_feature_selector_integration.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_feature_selector_integration.py b/tests/test_feature_selector_integration.py index af18514..1f2c7a6 100644 --- a/tests/test_feature_selector_integration.py +++ b/tests/test_feature_selector_integration.py @@ -37,5 +37,7 @@ def test_feature_selection_artificial_data_plsc(artificial_data, estimator): fitted_fs = fs.fit(X, y) selected_features = fitted_fs._selected_features - assert selected_features["min"] == [0, 1] # first two features - assert selected_features["max"] == [0, 3] # thirds and fourth feature + assert set(selected_features["min"]) == set([0, 1]) # first two features + assert set(selected_features["max"]) == set( + [0, 1, 2, 3] + ) # thirds and fourth feature