def test_setRandomState(self): experiment = Experiment(name='experiment 1', models=['rf', 'dt'], exp_type='regression') models = experiment.getModels() self.assertEqual( models['rf'].getConstructorArgs()['random_state'], 0 ) self.assertEqual( models['dt'].getConstructorArgs()['random_state'], 0 ) experiment.setRandomState(1) models = experiment.getModels() self.assertEqual( models['rf'].getConstructorArgs()['random_state'], 1 ) self.assertEqual( models['dt'].getConstructorArgs()['random_state'], 1 )
def test_addModel(self): experiment = Experiment('experiment_1') experiment.addModel('rf') dt_model = Model('decision tree', DecisionTreeClassifier, {'random_state': 0, 'max_depth': 2}) experiment.addModel(dt_model) models_dict = experiment.getModels() #print(models_dict) self.assertTrue( 'rf' in models_dict )
def test_init(self): experiment = Experiment() self.assertEqual( experiment.getName(), 'unnamed_experiment' ) self.assertEqual( experiment.getModels(), {} ) # Check if the name is set correctly name = 'exp_1' experiment = Experiment(name=name) self.assertEqual( experiment.name, name ) # Check that error is thrown if incorrect name is given name = ['bad', 'name'] try: experiment = Experiment(name=name) fail(self) except ValueError as ve: self.assertEqual( str(ve), 'Experiment name attribute must be string, not <class \'list\'>' ) name = 194500 try: experiment = Experiment(name=name) fail(self) except ValueError as ve: self.assertEqual( str(ve), 'Experiment name attribute must be string, not <class \'int\'>' ) # Check if the models is set correctly models = ['rf', 'dt'] experiment = Experiment(models=models) self.assertEqual( list(experiment.models_dict.keys()), models ) # Check is experiment type is set correctly experiment_type = 'classification' experiment = Experiment(exp_type=experiment_type) self.assertEqual( experiment.type_of_experiment, experiment_type ) # Check that error is thrown if incorrect experiment types are handed over experiment_type = ['hello', 'there'] try: experiment = Experiment( exp_type=experiment_type ) fail(self) except ValueError as ve: self.assertEqual( str(ve), 'Experiment type attribute must be string, not <class \'list\'>' ) experiment_type = 7331 try: experiment = Experiment( exp_type=experiment_type ) fail(self) except ValueError as ve: self.assertEqual( str(ve), 'Experiment type attribute must be string, not <class \'int\'>' ) experiment_type = 'definitely_not_regression_pls' try: experiment = Experiment( exp_type=experiment_type ) fail(self) except ValueError as ve: self.assertEqual( str(ve), 'The provided experiment type is not supported: \'definitely_not_regression_pls\'\nOnly these experiment types are supported: {}'.format(experiment._valid_experiment_types))