コード例 #1
0
ファイル: test_rvm.py プロジェクト: zhaobeile/scikit-rvm
    def test_regression_linear_noise(self):
        """Check regression works with a linear function with added noise."""
        clf = RVR(kernel='linear', alpha=1e11)

        x = np.arange(1, 101)
        y = x + 5

        np.random.seed(1)
        y = y + 0.1 * np.random.randn(y.shape[0])

        X = x[:, np.newaxis]

        clf.fit(X, y)
        score = clf.score(X, y)

        m_target = np.array([1, 5])
        rel_target = np.array([[1]])

        self.assertGreater(score, 0.99)
        np.testing.assert_allclose(clf.m_, m_target, rtol=1e-2)
        np.testing.assert_allclose(clf.relevance_, rel_target)
        self.assertAlmostEqual(clf.beta_, 126.583, places=3)

        prediction, mse = clf.predict(np.array([[50]]), eval_MSE=True)
        self.assertAlmostEqual(prediction[0], 55.006, places=3)
        self.assertAlmostEqual(mse[0], 0.00798, places=5)
コード例 #2
0
ファイル: test_rvm.py プロジェクト: zhaobeile/scikit-rvm
    def test_regression_sinc(self):
        """Check regression works with y=sinc(x)."""
        clf = RVR()
        x = np.linspace(0, 10, 101)
        y = np.sinc(x)

        np.random.seed(1)
        y = y + 0.1 * np.random.randn(y.shape[0])

        X = x[:, np.newaxis]

        clf.fit(X, y)
        score = clf.score(X, y)

        m_target = [
            1.117655e+00, -6.334513e-01, 5.868671e-01, -4.370936e-01,
            2.320311e-01, -4.638864e-05, -7.505325e-02, 6.133291e-02
        ]

        self.assertGreater(score, 0.85)
        np.testing.assert_allclose(clf.m_, m_target, rtol=1e-3)
        self.assertEqual(clf.relevance_.shape, (8, 1))

        prediction, mse = clf.predict(np.array([[0.5]]), eval_MSE=True)
        self.assertAlmostEqual(prediction[0], 0.611, places=3)
        self.assertAlmostEqual(mse[0], 0.00930, places=5)
コード例 #3
0
ファイル: test_rvm.py プロジェクト: zhaobeile/scikit-rvm
    def test_regression_linear(self):
        """Check regression works with a linear function."""
        clf = RVR(kernel='linear', alpha=1e11)

        x = np.arange(1, 100)
        y = x + 5

        X = x[:, np.newaxis]

        clf.fit(X, y)

        score = clf.score(X, y)

        m_target = np.array([1, 5])

        self.assertGreater(score, 0.99)
        np.testing.assert_allclose(clf.m_, m_target)

        prediction, mse = clf.predict(np.array([[50]]), eval_MSE=True)
        self.assertAlmostEqual(prediction[0], 55, places=3)
        self.assertAlmostEqual(mse[0], 6.18e-6, places=3)