def test_mmc(self): def_kwargs = { 'convergence_threshold': 0.001, 'diagonal': False, 'diagonal_c': 1.0, 'init': 'identity', 'max_iter': 100, 'max_proj': 10000, 'preprocessor': None, 'random_state': None, 'verbose': False } nndef_kwargs = {'diagonal': True} merged_kwargs = sk_repr_kwargs(def_kwargs, nndef_kwargs) self.assertEqual(remove_spaces(str(metric_learn.MMC(diagonal=True))), remove_spaces(f"MMC({merged_kwargs})")) def_kwargs = { 'convergence_threshold': 1e-06, 'diagonal': False, 'diagonal_c': 1.0, 'init': 'identity', 'max_iter': 100, 'max_proj': 10000, 'num_constraints': None, 'preprocessor': None, 'random_state': None, 'verbose': False } nndef_kwargs = {'max_iter': 1} merged_kwargs = sk_repr_kwargs(def_kwargs, nndef_kwargs) self.assertEqual( remove_spaces(str(metric_learn.MMC_Supervised(max_iter=1))), remove_spaces(f"MMC_Supervised({merged_kwargs})"))
def test_mmc(self): self.assertEqual(str(metric_learn.MMC()), """ MMC(A0=None, convergence_threshold=0.001, diagonal=False, diagonal_c=1.0, max_iter=100, max_proj=10000, preprocessor=None, verbose=False) """.strip('\n')) self.assertEqual(str(metric_learn.MMC_Supervised()), """ MMC_Supervised(A0=None, convergence_threshold=1e-06, diagonal=False, diagonal_c=1.0, max_iter=100, max_proj=10000, num_constraints=None, num_labeled='deprecated', preprocessor=None, verbose=False) """.strip('\n'))
def test_mmc(self): self.assertEqual( remove_spaces(str(metric_learn.MMC())), remove_spaces(""" MMC(A0='deprecated', convergence_threshold=0.001, diagonal=False, diagonal_c=1.0, init=None, max_iter=100, max_proj=10000, preprocessor=None, random_state=None, verbose=False) """)) self.assertEqual( remove_spaces(str(metric_learn.MMC_Supervised())), remove_spaces(""" MMC_Supervised(A0='deprecated', convergence_threshold=1e-06, diagonal=False, diagonal_c=1.0, init=None, max_iter=100, max_proj=10000, num_constraints=None, num_labeled='deprecated', preprocessor=None, random_state=None, verbose=False) """))
plot_tsne(X_itml, y) ###################################################################### # Mahalanobis Metric for Clustering # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # # MMC is an algorithm that will try to minimize the distance between similar # points, while ensuring that the sum of distances between dissimilar points is # higher than a threshold. This is done by optimizing a cost function # subject to an inequality constraint. # # - See more in the :ref:`User Guide <mmc>` # - See more in the documentation of the class :py:class:`MMC # <metric_learn.MMC>` mmc = metric_learn.MMC_Supervised() X_mmc = mmc.fit_transform(X, y) plot_tsne(X_mmc, y) ###################################################################### # Sparse Determinant Metric Learning # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ # # Implements an efficient sparse metric learning algorithm in high # dimensional space via an :math:`l_1`-penalized log-determinant # regularization. Compared to the most existing distance metric learning # algorithms, the algorithm exploits the sparsity nature underlying the # intrinsic high dimensional feature space. # # - See more in the :ref:`User Guide <sdml>`
def mmc(self, train_X, train_y, test_X): learner = ml.MMC_Supervised() train_X = learner.fit_transform(train_X, train_y) test_X = learner.transform(test_X) return train_X, test_X
def test_mmc(self): self.assertEqual(remove_spaces(str(metric_learn.MMC(diagonal=True))), remove_spaces("MMC(diagonal=True)")) self.assertEqual( remove_spaces(str(metric_learn.MMC_Supervised(max_iter=1))), remove_spaces("MMC_Supervised(max_iter=1)"))