示例#1
0
 def test_iris(self, basis):
   X, y = load_iris(return_X_y=True)
   scml = SCML_Supervised(basis=basis, n_basis=85, k_genuine=7, k_impostor=5,
                          random_state=42)
   scml.fit(X, y)
   csep = class_separation(scml.transform(X), y)
   assert csep < 0.24
示例#2
0
 def test_big_n_features(self):
   X, y = make_classification(n_samples=100, n_classes=3, n_features=60,
                              n_informative=60, n_redundant=0, n_repeated=0,
                              random_state=42)
   X = StandardScaler().fit_transform(X)
   scml = SCML_Supervised(random_state=42)
   scml.fit(X, y)
   csep = class_separation(scml.transform(X), y)
   assert csep < 0.7
示例#3
0
 def test_int_inputs_supervised(self, name):
     value = 1.0
     d = {name: value}
     scml = SCML_Supervised(**d)
     X = np.array([[0, 0], [1, 1], [3, 3], [4, 4]])
     y = np.array([1, 1, 0, 0])
     msg = ("%s should be an integer, instead it is of type"
            " %s" % (name, type(value)))
     with pytest.raises(ValueError) as raised_error:
         scml.fit(X, y)
     assert msg == raised_error.value.args[0]
示例#4
0
  def test_small_n_basis_lda(self):
    X = np.array([[0, 0], [1, 1], [2, 2], [3, 3]])
    y = np.array([0, 0, 1, 1])

    n_class = 2
    scml = SCML_Supervised(n_basis=n_class-1)
    msg = ("The number of basis is less than the number of classes, which may"
           " lead to poor discriminative performance.")
    with pytest.warns(UserWarning) as raised_warning:
      scml.fit(X, y)
    assert msg == raised_warning[0].message.args[0]
示例#5
0
 def test_iris(self, basis):
   """
   SCML applied to Iris dataset should give better results when
   computing class separation.
   """
   X, y = load_iris(return_X_y=True)
   before = class_separation(X, y)
   scml = SCML_Supervised(basis=basis, n_basis=85, k_genuine=7, k_impostor=5,
                          random_state=42)
   scml.fit(X, y)
   after = class_separation(scml.transform(X), y)
   assert before > after + 0.03  # It's better by a margin of 0.03
示例#6
0
    def test_big_n_basis_lda(self):
        X = np.array([[0, 0], [1, 1], [3, 3]])
        y = np.array([1, 2, 3])

        n_class = 3
        num_eig = min(n_class - 1, X.shape[1])
        n_basis = X.shape[0] * 2 * num_eig

        scml = SCML_Supervised(n_basis=n_basis)
        msg = ("Not enough samples to generate %d LDA bases, n_basis"
               "should be smaller than %d" % (n_basis, n_basis))
        with pytest.raises(ValueError) as raised_error:
            scml.fit(X, y)
        assert msg == raised_error.value.args[0]