示例#1
0
    def test_train_regression_sparse(self):
        # Lets add a test just to get everything working so we can refactor.
        X = [csr_matrix((np.ones(3), np.array([1, 4, 7]), np.array(range(4))), shape=(3, 10)),
             csr_matrix((np.ones(3), np.array([3, 8, 7]), np.array(range(4))), shape=(3, 10)),
             csr_matrix((np.ones(1), np.array([3]), np.array(range(2))), shape=(1, 10)),
             csr_matrix((np.ones(4), np.array([1, 4, 7, 9]), np.array(range(5))), shape=(4, 10))]
        y = [0, 1, 0, 1]
        model = Hcrf(5, 1.0)
        model.fit(X, y)
        actual = model.predict(X)

        expected = [0, 1, 0, 0]
        self.assertEqual(actual, expected)
示例#2
0
    def test_train_regression(self):
        # Lets add a test just to get everything working so we can refactor.
        X = [np.array([[1, 2], [5, 9], [7, 3.0]], dtype='float64'),
             np.array([[6, -2], [3, 3.0]], dtype='float64'),
             np.array([[1, -1.0]], dtype='float64'),
             np.array([[1, 1], [5, 3], [4, 2], [3.0, 3]], dtype='float64')]
        y = [0, 1, 0, 1]
        model = Hcrf(3)
        print X[0].dtype
        print
        model.fit(X, y)
        actual = model.predict(X)

        expected = [0, 1, 0, 1]
        self.assertEqual(actual, expected)