def test_scheduler(self): scheduler = ReduceOnWorsening() clf = algorithms.GRAM(max_iter=10, learning_rate=.01, scheduler=scheduler)\ .fit(self.KLtr, self.Ytr) scheduler = ReduceOnWorsening(multiplier=.6, min_lr=1e-4) clf = algorithms.GRAM(max_iter=10, learning_rate=.01, scheduler=scheduler)\ .fit(self.KLtr, self.Ytr)
def test_multiclass_ova(self): mkl = algorithms.GRAM(multiclass_strategy='ova', learner=SVC(), max_iter=2).fit(self.KLtr, self.Ytr) clf = multiclass.OneVsRestMKLClassifier(mkl).fit(self.KLtr, self.Ytr) classes = np.unique(self.Ytr) self.assertEqual(len(mkl.solution), len(classes)) for c in classes: self.assertListEqual(clf.solution[c].weights.tolist(), mkl.solution[c].weights.tolist())
def test_callbacks(self): earlystop_auc = callbacks.EarlyStopping(self.KLte, self.Yte, patience=5, cooldown=1, metric='auc') earlystop_acc = callbacks.EarlyStopping(self.KLte, self.Yte, patience=3, cooldown=2, metric='accuracy') cbks = [earlystop_auc, earlystop_acc] clf = algorithms.GRAM(max_iter=100, learning_rate=.01, callbacks=cbks) clf = clf.fit(self.KLtr, self.Ytr)
def test_callbacks(self): earlystop_auc = callbacks.EarlyStopping(self.KLte, self.Yte, patience=30, cooldown=2, metric='roc_auc') earlystop_acc = callbacks.EarlyStopping(self.KLte, self.Yte, patience=30, cooldown=2, metric='accuracy') monitor = callbacks.Monitor( metrics=[metrics.radius, metrics.margin, metrics.frobenius]) cbks = [earlystop_auc, earlystop_acc, monitor] clf = algorithms.GRAM(max_iter=60, learning_rate=.001, callbacks=cbks) clf = clf.fit(self.KLtr, self.Ytr) self.assertEqual(len(monitor.history), 3) print(monitor.objective) self.assertEqual(len(monitor.objective), 60)
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)))