Beispiel #1
0
    def test_streaming_linear_regression(self):
        X0 = numpy.array([[1, 0.5, 10., 5., -2.], [0, 0.4, 20, 4., 2.],
                          [0, 0.4, 19, 4.2, 2.], [0, 0.7, 18, 4.1, 1.4]],
                         dtype=float).T
        y0 = numpy.array([1., 2.1, 3.1, 3.9, 5.])

        for dim in (2, 3, 4):
            X = X0[:, :dim]
            y = y0
            algo1 = []
            for i in range(dim, X.shape[0] + 1):
                bk = linear_regression(X[:i], y[:i])
                algo1.append(bk)
            algo2 = []
            self.assertRaise(
                lambda: list(streaming_linear_regression(X.T, y)),  # pylint: disable=W0640
                RuntimeError)
            for i, bk in enumerate(streaming_linear_regression(X, y)):
                algo2.append(bk.copy())
                self.assertNotEmpty(bk)
                self.assertEqualArray(algo1[i], algo2[i])
            self.assertEqual(len(algo1), len(algo2))
Beispiel #2
0
 def test_profile(self):
     N = 1000
     X = rnd.randn(N, 10)
     eps = rnd.randn(N, 1) / 3
     y = X.sum(axis=1).reshape((X.shape[0], 1)) + eps
     y = y.ravel()
     res = self.profile(
         lambda: list(streaming_linear_regression_gram_schmidt(X, y)))
     if __name__ == "__main__":
         print(res[1])
     self.assertIn("streaming", res[1])
     res = self.profile(lambda: list(streaming_linear_regression(X, y)))
     if __name__ == "__main__":
         print(res[1])
     self.assertIn("streaming", res[1])