Skip to content

Commit

Permalink
tests added and updated, unnecessary memory usage removed
Browse files Browse the repository at this point in the history
  • Loading branch information
lukapecnik committed Dec 5, 2020
1 parent b64445a commit de8b1bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 1 addition & 4 deletions niaaml/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,9 @@ def evaluate(D, sol):
if i[1] is not None:
i[1].set_parameters(**args)

x = copy.deepcopy(self.__x)
y = copy.deepcopy(self.__y)

selected_features_mask = None

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
x_train, x_test, y_train, y_test = train_test_split(self.__x, self.__y, test_size=0.2)

if feature_selection_algorithm is None:
selected_features_mask = np.ones(x.shape[1], dtype=bool)
Expand Down
18 changes: 18 additions & 0 deletions niaaml/tests/test_feature_selection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from unittest import TestCase
from niaaml.preprocessing.feature_selection import ParticleSwarmOptimization, SelectKBest
from niaaml.data import CSVDataReader
import os

class FeatureSelectionTestCase(TestCase):
def setUp(self):
self.__algo1 = ParticleSwarmOptimization()
self.__algo2 = SelectKBest()

def test_select_features_works_fine(self):
data_reader = CSVDataReader(src=os.path.dirname(os.path.abspath(__file__)) + '/tests_files/dataset_header_classes.csv', has_header=True, contains_classes=True)

selected_features_mask = self.__algo1.select_features(data_reader.get_x(), data_reader.get_y())
self.assertEqual(data_reader.get_x().shape[1], len(selected_features_mask))

selected_features_mask = self.__algo2.select_features(data_reader.get_x(), data_reader.get_y())
self.assertEqual(data_reader.get_x().shape[1], len(selected_features_mask))
2 changes: 1 addition & 1 deletion niaaml/tests/test_pipeline_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def setUp(self):
)

def test_pipeline_optimizeer_run_works_fine(self):
pipeline = self.__pipeline_optimizer.run('Accuracy', 10, 10, 10, 10, 'ParticleSwarmAlgorithm')
pipeline = self.__pipeline_optimizer.run('Accuracy', 10, 10, 20, 20, 'ParticleSwarmAlgorithm')
self.assertIsInstance(pipeline, Pipeline)
self.assertTrue(isinstance(pipeline.get_classifier(), AdaBoost) or isinstance(pipeline.get_classifier(), Bagging))
self.assertTrue(isinstance(pipeline.get_feature_selection_algorithm(), SelectKBest) or isinstance(pipeline.get_feature_selection_algorithm(), SelectPercentile))
Expand Down

0 comments on commit de8b1bb

Please sign in to comment.