Beispiel #1
0
 def test_when_fitting_validation_strat_leave_group_out_splits_correct(self):
     validation_strat = LeaveOneGroupOut()
     groups = [0,1,0,1]
     self.trainer.prepare(model=MILES())
     self.trainer.fit(self.X_train, self.y_train, groups=groups, 
                      validation_strategy=validation_strat, verbose=0)
     self.assertEqual(self.trainer.tot_splits, 2)
Beispiel #2
0
 def test_when_prepare_with_metrics_then_metrics_are_calculated(self):
     validation_strat = LeaveOneGroupOut()
     groups = [0,1,0,1]
     self.trainer.prepare(model=MILES(), metrics=['acc','spec'])
     self.trainer.fit(self.X_train, self.y_train, groups=groups, 
                      validation_strategy=validation_strat, verbose=0)
     n_keys_train = len(self.trainer.metrics_train.metrics.keys())
     n_keys_val = len(self.trainer.metrics_train.metrics.keys())
     self.assertEqual(n_keys_train, 2)
     self.assertEqual(n_keys_val, 2)
Beispiel #3
0
class TestMILES(unittest.TestCase):
    def setUp(self):
        self.training_bag = np.random.normal(0, 1, (30, 3, 10))
        self.training_label = np.zeros(30)
        self.training_label[15:] = 1
        self.model = MILES()

    def test_miles_when_fit_array_less_than_3D_raise_exception(self):
        with self.assertRaises(DimensionError):
            self.model.fit([2, 3], [0, 0])

    def test_miles_when_predict_array_less_than_3D_raise_exception(self):
        with self.assertRaises(DimensionError):
            self.model.predict([2, 3])

    def test_miles_gives_correct_coefs_shape(self):
        self.model.fit(self.training_bag, self.training_label)
        coefs = self.model.coef_
        # the number of coefs corresponds to the total number of instances.
        self.assertEqual(len(coefs), 90)
Beispiel #4
0
 def setUp(self):
     self.training_bag = np.random.normal(0, 1, (30, 3, 10))
     self.training_label = np.zeros(30)
     self.training_label[15:] = 1
     self.model = MILES()
Beispiel #5
0
 def test_when_fitting_with_validation_and_validation_strat_splits_once(self):
     validation_strat = PredefinedSplit(test_fold=[-1,1,0,0])
     self.trainer.prepare(model=MILES())
     self.trainer.fit(self.X_train, self.y_train, self.X_val, self.y_val, 
                      validation_strategy=validation_strat, verbose=0)
     self.assertEqual(self.trainer.tot_splits, 1)
Beispiel #6
0
 def test_when_fitting_with_validation_splits_once(self):
     self.trainer.prepare(model=MILES())
     self.trainer.fit(self.X_train, self.y_train, self.X_val, self.y_val, verbose=0)
     self.assertEqual(self.trainer.tot_splits, 1)