Exemplo n.º 1
0
 def test_multiclass(self):
     data = load_iris()
     Xtr, Xte, Ytr, Yte = train_test_split(data.data,
                                           data.target,
                                           shuffle=True,
                                           train_size=100)
     Ktr = (Xtr @ Xtr.T)**2
     Kte = (Xte @ Xtr.T)**2
     y1 = algorithms.KOMD(kernel='poly', degree=2, coef0=0,
                          rbf_gamma=1).fit(Xtr, Ytr).predict(Xte)
     y2 = algorithms.KOMD(kernel='precomputed').fit(Ktr, Ytr).predict(Kte)
     self.assertListEqual(y1.tolist(), y2.tolist())
Exemplo n.º 2
0
 def test_EasyMKL(self):
     self.base_evaluation(algorithms.EasyMKL())
     self.base_evaluation(algorithms.EasyMKL(learner=SVC(C=10)))
     self.base_evaluation(
         algorithms.EasyMKL(learner=algorithms.KOMD(lam=1)))
     self.base_evaluation(
         algorithms.EasyMKL(solver='libsvm', learner=SVC(C=10)))
Exemplo n.º 3
0
 def test_PWMK(self):
     self.base_evaluation(algorithms.PWMK())
     self.base_evaluation(algorithms.PWMK(delta=.6, cv=2))
     cv = KFold(n_splits=5, shuffle=True, random_state=42)
     self.base_evaluation(
         algorithms.PWMK(delta=0, cv=cv, learner=SVC(C=100)))
     self.base_evaluation(
         algorithms.PWMK(delta=1, learner=algorithms.KOMD(lam=.2)))
Exemplo n.º 4
0
 def test_fit(self):
     K = self.Xtr @ self.Xtr.T
     clf = algorithms.KOMD().fit(self.Xtr, self.Ytr + 1)
     clf1 = algorithms.KOMD(kernel='precomputed').fit(K, self.Ytr + 1)
     params = clf1.get_params()
     self.assertTrue(params['lam'] == 0.1)
     self.assertTrue(params['kernel'] == 'precomputed')
     clf2 = algorithms.KOMD(kernel='rbf',
                            rbf_gamma=.01).fit(self.Xtr, self.Ytr + 1)
     clf3 = algorithms.KOMD(kernel='poly',
                            degree=2).fit(self.Xtr, self.Ytr + 1)
     clf4 = algorithms.KOMD(kernel='linear').fit(self.Xtr, self.Ytr + 1)
     y1 = clf1.decision_function(self.Xte @ self.Xtr.T)
     y2 = clf4.decision_function(self.Xte)
     self.assertListEqual(y1.tolist(), y2.tolist())
     y1 = clf1.predict(self.Xte @ self.Xtr.T)
     y2 = clf4.predict(self.Xte)
     self.assertListEqual(y1.tolist(), y2.tolist())
Exemplo n.º 5
0
 def test_GRAM(self):
     self.base_evaluation(algorithms.GRAM(max_iter=10))
     self.base_evaluation(algorithms.GRAM(max_iter=10, learner=SVC(C=10)))
     self.base_evaluation(
         algorithms.GRAM(max_iter=10, learner=algorithms.KOMD(lam=1)))
Exemplo n.º 6
0
 def test_AverageMKL(self):
     self.base_evaluation(algorithms.AverageMKL())
     self.base_evaluation(algorithms.AverageMKL(learner=SVC(C=10)))
     self.base_evaluation(
         algorithms.AverageMKL(learner=algorithms.KOMD(lam=1)))
Exemplo n.º 7
0
 def test_CKA(self):
     self.base_evaluation(algorithms.CKA(learner=SVC(C=10)))
     self.base_evaluation(algorithms.CKA(learner=algorithms.KOMD(lam=1)))
Exemplo n.º 8
0
 def test_FHeuristic(self):
     self.base_evaluation(algorithms.FHeuristic(learner=SVC(C=10)))
     self.base_evaluation(
         algorithms.FHeuristic(learner=algorithms.KOMD(lam=1)))