Пример #1
0
 def test_mindist(self):
     for k in range(1, 5):
         with self.subTest(k):
             X, Y = test_data.separable_hypercubes_data_set(48, k)
             means = pvml.mindist_train(X, Y)
             Yhat, scores = pvml.mindist_inference(X, means)
             self.assertListEqual(Y.tolist(), Yhat.tolist())
Пример #2
0
 def test_train(self):
     X, Y = test_data.separable_hypercubes_data_set(50, 2)
     net = pvml.CNN([X.shape[1], 2], [1])
     X = X.reshape(X.shape[0], 1, 1, X.shape[1])
     net.train(X, Y, lr=1e-1, steps=1000)
     Yhat, P = net.inference(X)
     self.assertListEqual(Y.tolist(), Yhat.tolist())
Пример #3
0
 def test_gaussian(self):
     for k in range(1, 6):
         with self.subTest(k):
             X, Y = test_data.separable_hypercubes_data_set(30, k)
             ms, vs, ps = pvml.gaussian_naive_bayes_train(X, Y)
             Yhat, scores = pvml.gaussian_naive_bayes_inference(
                 X, ms, vs, ps)
             self.assertListEqual(Y.tolist(), Yhat.tolist())
 def test_train2(self):
     for k in range(1, 6):
         with self.subTest(k):
             X, Y = test_data.separable_hypercubes_data_set(51, k)
             w, b = pvml.multinomial_logreg_train(X, Y, 1e-4, lr=1, steps=1000)
             P = pvml.multinomial_logreg_inference(X, w, b)
             Yhat = P.argmax(1)
             self.assertListEqual(Y.tolist(), Yhat.tolist())
Пример #5
0
 def test_train_pruning(self):
     tree = pvml.ClassificationTree()
     div = ["gini", "entropy", "error"]
     for k in range(1, 6):
         with self.subTest(k):
             X, Y = test_data.separable_hypercubes_data_set(51, k)
             tree.train(X, Y, diversity=div[k % 3], pruning_cv=5)
             Yhat = tree.inference(X)[0]
             self.assertListEqual(Y.tolist(), Yhat.tolist())
Пример #6
0
 def test_train2(self):
     X, Y = test_data.separable_hypercubes_data_set(50, 2)
     w, b = pvml.svm_train(X, Y, 0.0001, lr=10, steps=1000)
     Yhat, P = pvml.svm_inference(X, w, b)
     self.assertListEqual(Y.tolist(), Yhat.tolist())
     self.assertListEqual(Yhat.tolist(), (P > 0).tolist())
Пример #7
0
 def test_dump(self):
     tree = pvml.ClassificationTree()
     X, Y = test_data.separable_hypercubes_data_set(21, 3)
     tree.train(X, Y)
     s = tree._dumps()
     self.assertTrue(len(s.splitlines()) > 3)
Пример #8
0
 def test_train2(self):
     X, Y = test_data.separable_hypercubes_data_set(12, 2)
     alpha, b = pvml.ksvm_train(X, Y, "polynomial", 2, 0, lr=10, steps=1000)
     Yhat, P = pvml.ksvm_inference(X, X, alpha, b, "polynomial", 2)
     self.assertListEqual(Y.tolist(), Yhat.tolist())
     self.assertListEqual(Yhat.tolist(), (P > 0).tolist())
Пример #9
0
 def test_train2(self):
     X, Y = test_data.separable_hypercubes_data_set(50, 2)
     w, b = pvml.perceptron_train(X, Y)
     Yhat, Z = pvml.perceptron_inference(X, w, b)
     self.assertListEqual(Y.tolist(), Yhat.tolist())
Пример #10
0
 def test_gaussian2(self):
     X, Y = test_data.separable_hypercubes_data_set(50, 2)
     priors = np.array([0.0, 1.0])
     ms, vs, priors = pvml.gaussian_naive_bayes_train(X, Y, priors)
     Yhat, _ = pvml.gaussian_naive_bayes_inference(X, ms, vs, priors)
     self.assertListEqual([1] * Y.size, Yhat.tolist())
Пример #11
0
 def test_train_l2(self):
     X, Y = test_data.separable_hypercubes_data_set(50, 2)
     w, b = pvml.logreg_train(X, Y, 0.0001, lr=10, steps=1000)
     P = pvml.logreg_inference(X, w, b)
     Yhat = (P > 0.5).astype(int)
     self.assertListEqual(Y.tolist(), Yhat.tolist())