def test_HintSVM(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:5], [None] * (len(self.y) - 5)])) qs = HintSVM(trn_ds, random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([24, 235, 228, 209, 18, 143, 119, 90, 149, 207]))
def test_quire(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:5], [None] * (len(self.y) - 5)])) qs = QUIRE(trn_ds) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([117, 175, 256, 64, 103, 118, 180, 159, 129, 235]))
def test_DensityWeightedUncertaintySampling(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:10], [None] * (len(self.y) - 10)])) qs = DWUS(trn_ds, random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([30, 179, 104, 186, 28, 65, 142, 62, 257, 221]))
def test_RandomSampling(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:5], [None] * (len(self.y) - 5)])) qs = RandomSampling(trn_ds, random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([33, 143, 198, 29, 248, 92, 236, 212, 185, 163]))
def test_UcertaintySamplingLc(self): random.seed(1126) trn_ds = Dataset( self.X, np.concatenate([self.y[:10], [None] * (len(self.y) - 10)])) qs = UncertaintySampling(trn_ds, method='lc', model=LogisticRegression()) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([145, 66, 82, 37, 194, 60, 191, 211, 245, 131]))
def test_quire_mykernel(self): def my_kernel(X, Y): return np.dot(X, Y.T) np.random.seed(1126) trn_ds = Dataset( self.X, np.concatenate([self.y[:5], [None] * (len(self.y) - 5)])) qs = QUIRE(trn_ds, kernel=my_kernel) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([9, 227, 176, 110, 52, 117, 228, 205, 103, 175]))
def test_query_by_committee_kl_divergence(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:10], [None] * (len(self.y) - 10)])) qs = QueryByCommittee(trn_ds, disagreement='kl_divergence', models=[ LogisticRegression(C=1.0), LogisticRegression(C=0.01), LogisticRegression(C=100) ], random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([228, 111, 162, 243, 213, 122, 110, 108, 156, 37]))
def test_query_by_committee_vote(self): #self.skipTest("In this version we randomize make queries") trn_ds = Dataset( self.X, np.concatenate([self.y[:10], [None] * (len(self.y) - 10)])) qs = QueryByCommittee(trn_ds, disagreement='vote', models=[ LogisticRegression(C=1.0), LogisticRegression(C=0.01), LogisticRegression(C=100) ], random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal(qseq, np.array([10, 12, 11, 13, 16, 14, 17, 18, 19, 21]))
def test_ActiveLearningByLearning(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:10], [None] * (len(self.y) - 10)])) qs = ActiveLearningByLearning(trn_ds, T=self.quota, query_strategies=[ UncertaintySampling( trn_ds, model=LogisticRegression()), HintSVM(trn_ds, random_state=1126) ], model=LogisticRegression(), random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([173, 103, 133, 184, 187, 147, 251, 83, 93, 33]))
def test_ALBLTestCase(self): trn_ds = Dataset( self.X, np.concatenate([self.y[:10], [None] * (len(self.y) - 10)])) qs = ActiveLearningByLearning( trn_ds, T=self.quota, query_strategies=[ UncertaintySampling(trn_ds, model=SVM(kernel="linear", decision_function_shape="ovr")), QUIRE(trn_ds), RandomSampling(trn_ds) ], model=SVM(kernel="linear", decision_function_shape="ovr"), random_state=1126) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal( qseq, np.array([173, 103, 133, 184, 187, 147, 251, 83, 93, 33]))
def test_quire(self): trn_ds = Dataset(self.X, np.concatenate([self.y[:10], [None] * 10])) qs = RandomSampling(trn_ds, random_state=2019) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal(qseq, np.array([18, 12, 19, 16, 10, 11, 14, 13, 15, 17]))
def test_quire(self): trn_ds = Dataset(self.X, np.concatenate([self.y[:10], [None] * 10])) qs = QUIRE(trn_ds) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal(qseq, np.array([10, 11, 12, 13, 14, 15, 16, 18, 19, 17]))
def test_quire(self): trn_ds = Dataset(self.X, np.concatenate([self.y[:6], [None] * 4])) qs = QUIRE(trn_ds) qseq = run_qs(trn_ds, qs, self.y, self.quota) assert_array_equal(qseq, np.array([6, 7, 9, 8]))