def test_sdml(self): def_kwargs = { 'balance_param': 0.5, 'preprocessor': None, 'prior': 'identity', 'random_state': None, 'sparsity_param': 0.01, 'verbose': False } nndef_kwargs = {'verbose': True} merged_kwargs = sk_repr_kwargs(def_kwargs, nndef_kwargs) self.assertEqual(remove_spaces(str(metric_learn.SDML(verbose=True))), remove_spaces(f"SDML({merged_kwargs})")) def_kwargs = { 'balance_param': 0.5, 'num_constraints': None, 'preprocessor': None, 'prior': 'identity', 'random_state': None, 'sparsity_param': 0.01, 'verbose': False } nndef_kwargs = {'sparsity_param': 0.5} merged_kwargs = sk_repr_kwargs(def_kwargs, nndef_kwargs) self.assertEqual( remove_spaces(str( metric_learn.SDML_Supervised(sparsity_param=0.5))), remove_spaces(f"SDML_Supervised({merged_kwargs})"))
def test_sdml(self): self.assertEqual(remove_spaces(str(metric_learn.SDML(verbose=True))), remove_spaces("SDML(verbose=True)")) self.assertEqual( remove_spaces(str( metric_learn.SDML_Supervised(sparsity_param=0.5))), remove_spaces("SDML_Supervised(sparsity_param=0.5)"))
def test_sdml(self): self.assertEqual(str(metric_learn.SDML()), "SDML(balance_param=0.5, preprocessor=None, " "sparsity_param=0.01, use_cov=True,\n verbose=False)") self.assertEqual(str(metric_learn.SDML_Supervised()), """ SDML_Supervised(balance_param=0.5, num_constraints=None, num_labeled='deprecated', preprocessor=None, sparsity_param=0.01, use_cov=True, verbose=False) """.strip('\n'))
def test_sdml(self): self.assertEqual( remove_spaces(str(metric_learn.SDML())), remove_spaces(""" SDML(balance_param=0.5, preprocessor=None, prior=None, random_state=None, sparsity_param=0.01, use_cov='deprecated', verbose=False) """)) self.assertEqual( remove_spaces(str(metric_learn.SDML_Supervised())), remove_spaces(""" SDML_Supervised(balance_param=0.5, num_constraints=None, num_labeled='deprecated', preprocessor=None, prior=None, random_state=None, sparsity_param=0.01, use_cov='deprecated', verbose=False) """))
def test_string_repr(self): # we don't test LMNN here because it could be python_LMNN self.assertEqual(str(metric_learn.Covariance()), "Covariance()") self.assertEqual(str(metric_learn.NCA()), "NCA(learning_rate=0.01, max_iter=100, num_dims=None)") self.assertEqual(str(metric_learn.LFDA()), "LFDA(dim=None, k=7, metric='weighted')") self.assertEqual(str(metric_learn.ITML()), """ ITML(convergence_threshold=0.001, gamma=1.0, max_iters=1000, verbose=False) """.strip('\n')) self.assertEqual(str(metric_learn.ITML_Supervised()), """ ITML_Supervised(A0=None, bounds=None, convergence_threshold=0.001, gamma=1.0, max_iters=1000, num_constraints=None, num_labeled=inf, verbose=False) """.strip('\n')) self.assertEqual(str(metric_learn.LSML()), "LSML(max_iter=1000, tol=0.001, verbose=False)") self.assertEqual(str(metric_learn.LSML_Supervised()), """ LSML_Supervised(max_iter=1000, num_constraints=None, num_labeled=inf, prior=None, tol=0.001, verbose=False, weights=None) """.strip('\n')) self.assertEqual(str(metric_learn.SDML()), """ SDML(balance_param=0.5, sparsity_param=0.01, use_cov=True, verbose=False) """.strip('\n')) self.assertEqual(str(metric_learn.SDML_Supervised()), """ SDML_Supervised(balance_param=0.5, num_constraints=None, num_labeled=inf, sparsity_param=0.01, use_cov=True, verbose=False) """.strip('\n')) self.assertEqual(str(metric_learn.RCA()), "RCA(dim=None)") self.assertEqual(str(metric_learn.RCA_Supervised()), "RCA_Supervised(chunk_size=2, dim=None, num_chunks=100)") self.assertEqual(str(metric_learn.MLKR()), """ MLKR(A0=None, alpha=0.0001, epsilon=0.01, max_iter=1000, num_dims=None) """.strip('\n'))
def sdml(self, train_X, train_y, test_X, bal, spa): learner = ml.SDML(balance_param=bal, sparsity_param=spa) train_X = learner.fit_transform(train_X, train_y) test_X = learner.transform(test_X) return train_X, test_X