Esempio n. 1
0
 def test_get_critical_set_indices_single(self):
     x = np.concatenate([self.x, np.array([self.x[0, :]] * 5)], axis=0)
     x_min = x[:1, :]
     x_maj = x[1:, :]
     critical_set = BiasedRFClassifier(k_nearest_neighbor=5)._get_crtical_set_indices(x_maj, x_min)
     # confirm that the indices are the nearest neighbors
     self.assertEqual(list(range(9, 14)), critical_set)
Esempio n. 2
0
 def test_get_critical_x_shape(self):
     x = np.concatenate([self.x, np.array([self.x[0, :]] * 5)], axis=0)
     y = np.zeros((len(x), 1))
     y[0] = 1
     _, critical_y = BiasedRFClassifier(k_nearest_neighbor=5)._get_critical_set(x, y)
     # confirm the critical y is the minor (label=1) and 5 major (label=0) stacked
     self.assertListEqual([1,0,0,0,0,0], critical_y.tolist())
Esempio n. 3
0
 def test_get_critical_x_shape(self):
     x = np.concatenate([self.x, np.array([self.x[0, :]] * 5)], axis=0)
     y = np.zeros((len(x), 1))
     y[0] = 1
     critical_x, _ = BiasedRFClassifier(k_nearest_neighbor=5)._get_critical_set(x, y)
     # confirm getting the single minor and 5 cloeset => total 6 rows back
     self.assertEqual(6, critical_x.shape[0])
     self.assertEqual(x.shape[1], critical_x.shape[1])
Esempio n. 4
0
 def test_get_critical_set_indices_in_major_set(self):
     x_min = self.x[:2, :]
     x_maj = self.x[2:, :]
     critical_set = BiasedRFClassifier(k_nearest_neighbor=5)._get_crtical_set_indices(x_maj, x_min)
     # confirm that the indices are the nearest neighbors
     major_indices = list(range(len(x_maj)))
     for idx in critical_set:
         with self.subTest(idx=idx):
             self.assertTrue(idx in major_indices)
Esempio n. 5
0
 def test_get_critical_set_indices_overlap_neighbors(self):
     # create dataset where x_min are two points with the same features
     # so the critical set we get should just be 5 points (both have the same neighbors)
     self.x[1, :] = self.x[0, :]
     x_min = self.x[:2, :]
     x_maj = self.x[2:, :]
     critical_set = BiasedRFClassifier(k_nearest_neighbor=5)._get_crtical_set_indices(x_maj, x_min)
     # confirm that the indices are the nearest neighbors
     self.assertEqual(5, len(critical_set))
Esempio n. 6
0
 def test_predict_logic(self):
     model = BiasedRFClassifier(k_nearest_neighbor=5)
     model.fit(self.x, self.imbalance_y)
     pred = model.predict(self.x)
     self.assertEqual(len(self.imbalance_y), len(pred))
     print(pred)
Esempio n. 7
0
 def test_fit_logic(self):
     model = BiasedRFClassifier(k_nearest_neighbor=5)
     model.fit(self.x, self.imbalance_y)
     self.assertTrue(model._is_fitted())