コード例 #1
0
 def test_lsml(self):
     def_kwargs = {
         'max_iter': 1000,
         'preprocessor': None,
         'prior': 'identity',
         'random_state': None,
         'tol': 0.001,
         'verbose': False
     }
     nndef_kwargs = {'tol': 0.1}
     merged_kwargs = sk_repr_kwargs(def_kwargs, nndef_kwargs)
     self.assertEqual(remove_spaces(str(metric_learn.LSML(tol=0.1))),
                      remove_spaces(f"LSML({merged_kwargs})"))
     def_kwargs = {
         'max_iter': 1000,
         'num_constraints': None,
         'preprocessor': None,
         'prior': 'identity',
         'random_state': None,
         'tol': 0.001,
         'verbose': False,
         'weights': None
     }
     nndef_kwargs = {'verbose': True}
     merged_kwargs = sk_repr_kwargs(def_kwargs, nndef_kwargs)
     self.assertEqual(
         remove_spaces(str(metric_learn.LSML_Supervised(verbose=True))),
         remove_spaces(f"LSML_Supervised({merged_kwargs})"))
コード例 #2
0
    def test_lsml(self):
        self.assertEqual(
            str(metric_learn.LSML()),
            "LSML(max_iter=1000, prior=None, 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'))
コード例 #3
0
    def test_lsml(self):
        self.assertEqual(
            remove_spaces(str(metric_learn.LSML())),
            remove_spaces(
                "LSML(max_iter=1000, preprocessor=None, prior=None, tol=0.001, "
                "verbose=False)"))
        self.assertEqual(
            remove_spaces(str(metric_learn.LSML_Supervised())),
            remove_spaces("""
LSML_Supervised(max_iter=1000, num_constraints=None, num_labeled='deprecated',
        preprocessor=None, prior=None, tol=0.001, verbose=False,
        weights=None)
"""))
コード例 #4
0
  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'))
コード例 #5
0
 def lsml(self, train_X, train_y, test_X):
     learner = ml.LSML()
     train_X = learner.fit_transform(train_X, train_y)
     test_X = learner.transform(test_X)
     return train_X, test_X
コード例 #6
0
 def test_lsml(self):
     self.assertEqual(remove_spaces(str(metric_learn.LSML(tol=0.1))),
                      remove_spaces("LSML(tol=0.1)"))
     self.assertEqual(
         remove_spaces(str(metric_learn.LSML_Supervised(verbose=True))),
         remove_spaces("LSML_Supervised(verbose=True)"))