def test_classification_kmeans_intercept_weights(self):
     iris = datasets.load_iris()
     X, y = iris.data, iris.target
     clr = ClassifierAfterKMeans()
     clr.fit(X, y, sample_weight=numpy.ones((X.shape[0], )))
     acc = clr.score(X, y)
     self.assertGreater(acc, 0)
 def test_classification_kmeans(self):
     iris = datasets.load_iris()
     X, y = iris.data, iris.target
     clr = ClassifierAfterKMeans()
     clr.fit(X, y)
     acc = clr.score(X, y)
     self.assertGreater(acc, 0)
     prob = clr.predict_proba(X)
     self.assertEqual(prob.shape[1], 3)
     dec = clr.decision_function(X)
     self.assertEqual(prob.shape, dec.shape)
Пример #3
0
 def test_classification_kmeans_intercept_weights(self):
     iris = datasets.load_iris()
     X, y = iris.data, iris.target
     clr = ClassifierAfterKMeans()
     try:
         clr.fit(X, y, sample_weight=numpy.ones((X.shape[0], )))
     except AttributeError as e:
         if compare_module_version(sklver, "0.24") < 0:
             return
         raise e
     acc = clr.score(X, y)
     self.assertGreater(acc, 0)
Пример #4
0
 def test_classification_kmeans(self):
     iris = datasets.load_iris()
     X, y = iris.data, iris.target
     clr = ClassifierAfterKMeans()
     try:
         clr.fit(X, y)
     except AttributeError as e:
         if compare_module_version(sklver, "0.24") < 0:
             return
         raise e
     acc = clr.score(X, y)
     self.assertGreater(acc, 0)
     prob = clr.predict_proba(X)
     self.assertEqual(prob.shape[1], 3)
     dec = clr.decision_function(X)
     self.assertEqual(prob.shape, dec.shape)
 def test_classification_kmeans_relevance(self):
     state = RandomState(seed=0)
     Xs = []
     Ys = []
     n = 20
     for i in range(0, 5):
         for j in range(0, 4):
             x1 = state.rand(n) + i * 1.1
             x2 = state.rand(n) + j * 1.1
             Xs.append(numpy.vstack([x1, x2]).T)
             cl = state.randint(0, 4)
             Ys.extend([cl for i in range(n)])
     X = numpy.vstack(Xs)
     Y = numpy.array(Ys)
     clk = ClassifierAfterKMeans(c_n_clusters=6, c_random_state=state)
     clk.fit(X, Y)
     score = clk.score(X, Y)
     self.assertGreater(score, 0.95)
Пример #6
0
 def test_classification_kmeans_relevance(self):
     state = RandomState(seed=0)
     Xs = []
     Ys = []
     n = 20
     for i in range(0, 5):
         for j in range(0, 4):
             x1 = state.rand(n) + i * 1.1
             x2 = state.rand(n) + j * 1.1
             Xs.append(numpy.vstack([x1, x2]).T)
             cl = state.randint(0, 4)
             Ys.extend([cl for i in range(n)])
     X = numpy.vstack(Xs)
     Y = numpy.array(Ys)
     clk = ClassifierAfterKMeans(c_n_clusters=6, c_random_state=state)
     try:
         clk.fit(X, Y)
     except AttributeError as e:
         if compare_module_version(sklver, "0.24") < 0:
             return
         raise e
     score = clk.score(X, Y)
     self.assertGreater(score, 0.95)