Example #1
0
 def test_linear_regress(self):
     data = Series(self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]))
     x = array([
         array([1, 0, 0, 0, 0, 0]),
         array([0, 1, 0, 0, 0, 0])
     ])
     model = RegressionModel.load(x, "linear")
     result = model.fit(data)
     assert(allclose(result.select('betas').values().collect()[0], array([-2.7, -1.9])))
     assert(allclose(result.select('stats').values().collect()[0], array([0.42785299])))
     assert(allclose(result.select('resid').values().collect()[0], array([0, 0, 2, 0.9, -0.8, -2.1])))
Example #2
0
 def test_linearRegress(self):
     data = Series(self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]))
     x = array([
         array([1, 0, 0, 0, 0, 0]),
         array([0, 1, 0, 0, 0, 0])
     ])
     model = RegressionModel.load(x, "linear")
     result = model.fit(data)
     # check accuracy of results
     assert(allclose(result.select('betas').values().collect()[0], array([-2.7, -1.9])))
     assert(allclose(result.select('stats').values().collect()[0], array([0.42785299])))
     assert(allclose(result.select('resid').values().collect()[0], array([0, 0, 2, 0.9, -0.8, -2.1])))
     # check indexing of outputs
     assert(allclose(result.select('betas').index, array([0, 1])))
     assert(allclose(result.select('resid').index, array([0, 1, 2, 3, 4, 5])))
     assert(result.select('stats').index == 'stats')
Example #3
0
 def test_blinear_regress(self):
     data = Series(self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]))
     x1 = array([
         array([1, 0, 1, 0, 1, 0]),
         array([0, 1, 0, 1, 0, 1])
     ])
     x2 = array([
         array([1, 1, 0, 0, 0, 0]),
         array([0, 0, 1, 1, 0, 0]),
         array([0, 0, 0, 0, 1, 1])
     ])
     model = RegressionModel.load((x1, x2), "bilinear")
     result = model.fit(data)
     tol = 1E-4  # to handle rounding errors
     assert(allclose(result.select('betas').values().collect()[0], array([-3.1249, 5.6875, 0.4375]), atol=tol))
     assert(allclose(result.select('stats').values().collect()[0], array([0.6735]), tol))
     assert(allclose(result.select('resid').values().collect()[0], array([0, -0.8666, 0, 1.9333, 0, -1.0666]), atol=tol))
Example #4
0
 def test_linearRegress(self):
     data = Series(
         self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]))
     x = array([array([1, 0, 0, 0, 0, 0]), array([0, 1, 0, 0, 0, 0])])
     model = RegressionModel.load(x, "linear")
     result = model.fit(data)
     # check accuracy of results
     assert (allclose(
         result.select('betas').values().collect()[0], array([-2.7, -1.9])))
     assert (allclose(
         result.select('stats').values().collect()[0], array([0.42785299])))
     assert (allclose(
         result.select('resid').values().collect()[0],
         array([0, 0, 2, 0.9, -0.8, -2.1])))
     # check indexing of outputs
     assert (allclose(result.select('betas').index, array([0, 1])))
     assert (allclose(
         result.select('resid').index, array([0, 1, 2, 3, 4, 5])))
     assert (result.select('stats').index == ['stats'])
Example #5
0
 def test_bilinearRegress(self):
     data = Series(
         self.sc.parallelize([(1, array([1.5, 2.3, 6.2, 5.1, 3.4, 2.1]))]))
     x1 = array([array([1, 0, 1, 0, 1, 0]), array([0, 1, 0, 1, 0, 1])])
     x2 = array([
         array([1, 1, 0, 0, 0, 0]),
         array([0, 0, 1, 1, 0, 0]),
         array([0, 0, 0, 0, 1, 1])
     ])
     model = RegressionModel.load((x1, x2), "bilinear")
     result = model.fit(data)
     tol = 1E-4  # to handle rounding errors
     assert (allclose(result.select('betas').values().collect()[0],
                      array([-3.1249, 5.6875, 0.4375]),
                      atol=tol))
     assert (allclose(
         result.select('stats').values().collect()[0], array([0.6735]),
         tol))
     assert (allclose(result.select('resid').values().collect()[0],
                      array([0, -0.8666, 0, 1.9333, 0, -1.0666]),
                      atol=tol))