def test_fit_instantiates_component(self): """Make sure that if a preprocessor is added, it's fit method is called""" preprocessing_components.add_preprocessor(CrashPreprocessor) # We reduce the search space as forbidden clauses prevent to instantiate # the user defined preprocessor manually cls = SimpleClassificationPipeline(include={'classifier': ['random_forest']}) cs = cls.get_hyperparameter_search_space() self.assertIn('CrashPreprocessor', str(cs)) config = cs.sample_configuration() try: config['feature_preprocessor:__choice__'] = 'CrashPreprocessor' except Exception as e: # In case of failure clean up the components and print enough information # to clean up with check in the future del preprocessing_components._addons.components['CrashPreprocessor'] self.fail("cs={} config={} Exception={}".format(cs, config, e)) cls.set_hyperparameters(config) with self.assertRaisesRegex( ValueError, "Make sure fit is called" ): cls.fit( X=np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), y=np.array([1, 0, 1, 1]) ) del preprocessing_components._addons.components['CrashPreprocessor']
def test_add_preprocessor(self): self.assertEqual(len(preprocessing_components._addons.components), 0) preprocessing_components.add_preprocessor(DummyPreprocessor) self.assertEqual(len(preprocessing_components._addons.components), 1) cs = SimpleClassificationPipeline().get_hyperparameter_search_space() self.assertIn('DummyPreprocessor', str(cs)) del preprocessing_components._addons.components['DummyPreprocessor']
def test_fit_instantiates_component(self): """Make sure that if a preprocessor is added, it's fit method is called""" preprocessing_components.add_preprocessor(CrashPreprocessor) cls = SimpleClassificationPipeline() cs = cls.get_hyperparameter_search_space() self.assertIn('CrashPreprocessor', str(cs)) config = cs.sample_configuration() config['feature_preprocessor:__choice__'] = 'CrashPreprocessor' cls.set_hyperparameters(config) with self.assertRaisesRegex( ValueError, "Make sure fit is called" ): cls.fit( X=np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), y=np.array([1, 0, 1, 1]) ) del preprocessing_components._addons.components['CrashPreprocessor']