def test_multilabel(self):
     x = Classifier(CONFIG)
     tdata = np.array([
         [0, 1, 0],
         [0, 0, 1],
         [1, 0, 0],
     ], dtype='f8')
     ttargets = np.array([1, 2, 0])
     x.partial_fit(tdata, ttargets)
     y = x.predict(np.array([
         [1, 0, 0],
         [0, 1, 0],
         [0, 0, 1],
     ], dtype='f8'))
     self.assertTrue(isinstance(y, np.ndarray))
     self.assertEqual(y.dtype, np.int32)
     self.assertTrue(np.equal(y, np.array([0, 1, 2])).all())
     y = x.decision_function(
         np.array([
             [1, 0, 0],
             [0, 1, 0],
             [0, 0, 1],
         ], dtype='f8'))
     self.assertTrue(isinstance(y, np.ndarray))
     self.assertEqual((3, 3), y.shape)
     self.assertTrue(y[0][0] > y[0][1] and y[0][0] > y[0][2])
     self.assertTrue(y[1][1] > y[1][0] and y[1][1] > y[1][2])
     self.assertTrue(y[2][2] > y[2][0] and y[2][2] > y[2][1])
    def test_sparse(self):
        from scipy.sparse import csr_matrix

        x = Classifier(CONFIG)
        tdata = csr_matrix(np.array([
            [1, 0, 1],
            [0, 1, 1],
        ], dtype='f8'))
        ttargets = np.array([1, 0])
        x.partial_fit(tdata, ttargets)
        y = x.predict(
            csr_matrix(np.array([
                [1, 0, 0],
                [0, 1, 0],
            ], dtype='f8')))
        self.assertEqual(1, y[0])
        self.assertEqual(0, y[1])
        y = x.decision_function(
            csr_matrix(np.array([
                [1, 0, 0],
                [0, 1, 0],
            ], dtype='f8')))
        self.assertEqual(2, len(y))
        self.assertTrue(not isinstance(y[0], (list, tuple, np.ndarray)))
        self.assertTrue(y[0] > 0)
        self.assertTrue(y[1] < 0)
    def test_numpy(self):
        x = Classifier(CONFIG)
        tdata = np.array([
            [1, 0, 1],
            [0, 1, 1],
        ], dtype='f8')
        ttargets = np.array([1, 0])
        x.partial_fit(tdata, ttargets)
        y = x.predict(np.array([
            [1, 0, 0],
            [0, 1, 0],
        ], dtype='f8'))
        self.assertEqual(1, y[0])
        self.assertEqual(0, y[1])
        y = x.decision_function(np.array([
            [1, 0, 0],
            [0, 1, 0],
        ], dtype='f8'))
        self.assertEqual(2, len(y))
        self.assertTrue(not isinstance(y[0], (list, tuple, np.ndarray)))
        self.assertTrue(y[0] > 0)
        self.assertTrue(y[1] < 0)
        self.assertEqual([0, 1], sorted(x.classes_))

        model = x.save_bytes()
        x = Classifier(CONFIG)
        x.load_bytes(model)
        self.assertEqual([0, 1], sorted(x.classes_))
        y = x.predict(np.array([
            [1, 0, 0],
            [0, 1, 0],
        ], dtype='f8'))
        self.assertEqual(1, y[0])
        self.assertEqual(0, y[1])
 def test_multilabel(self):
     x = Classifier(CONFIG)
     tdata = np.array([
         [0, 1, 0],
         [0, 0, 1],
         [1, 0, 0],
     ], dtype='f8')
     ttargets = np.array([1, 2, 0])
     x.partial_fit(tdata, ttargets)
     y = x.predict(np.array([
         [1, 0, 0],
         [0, 1, 0],
         [0, 0, 1],
     ], dtype='f8'))
     self.assertTrue(isinstance(y, np.ndarray))
     self.assertEqual(y.dtype, np.int32)
     self.assertTrue(np.equal(y, np.array([0, 1, 2])).all())
     y = x.decision_function(np.array([
         [1, 0, 0],
         [0, 1, 0],
         [0, 0, 1],
     ], dtype='f8'))
     self.assertTrue(isinstance(y, np.ndarray))
     self.assertEqual((3, 3), y.shape)
     self.assertTrue(y[0][0] > y[0][1] and y[0][0] > y[0][2])
     self.assertTrue(y[1][1] > y[1][0] and y[1][1] > y[1][2])
     self.assertTrue(y[2][2] > y[2][0] and y[2][2] > y[2][1])
 def test_numpy(self):
     x = Classifier(CONFIG)
     tdata = np.array([
         [1, 0, 1],
         [0, 1, 1],
     ], dtype='f8')
     ttargets = np.array([1, 0])
     x.partial_fit(tdata, ttargets)
     y = x.predict(np.array([
         [1, 0, 0],
         [0, 1, 0],
     ], dtype='f8'))
     self.assertEqual(1, y[0])
     self.assertEqual(0, y[1])
     y = x.decision_function(np.array([
         [1, 0, 0],
         [0, 1, 0],
     ], dtype='f8'))
     self.assertEqual(2, len(y))
     self.assertTrue(not isinstance(y[0], (list, tuple, np.ndarray)))
     self.assertTrue(y[0] > 0)
     self.assertTrue(y[1] < 0)
    def test_sparse(self):
        from scipy.sparse import csr_matrix

        x = Classifier(CONFIG)
        tdata = csr_matrix(np.array([
            [1, 0, 1],
            [0, 1, 1],
        ], dtype='f8'))
        ttargets = np.array([1, 0])
        x.partial_fit(tdata, ttargets)
        y = x.predict(csr_matrix(np.array([
            [1, 0, 0],
            [0, 1, 0],
        ], dtype='f8')))
        self.assertEqual(1, y[0])
        self.assertEqual(0, y[1])
        y = x.decision_function(csr_matrix(np.array([
            [1, 0, 0],
            [0, 1, 0],
        ], dtype='f8')))
        self.assertEqual(2, len(y))
        self.assertTrue(not isinstance(y[0], (list, tuple, np.ndarray)))
        self.assertTrue(y[0] > 0)
        self.assertTrue(y[1] < 0)