Repository: mahout Updated Branches: refs/heads/master 5afdc68e0 -> ba37a8aa2
MAHOUT-1924 Add Unit Test for DurbinWatson Test closes apache/mahout#282 Project: http://git-wip-us.apache.org/repos/asf/mahout/repo Commit: http://git-wip-us.apache.org/repos/asf/mahout/commit/ba37a8aa Tree: http://git-wip-us.apache.org/repos/asf/mahout/tree/ba37a8aa Diff: http://git-wip-us.apache.org/repos/asf/mahout/diff/ba37a8aa Branch: refs/heads/master Commit: ba37a8aa20d0969d2db5d810ecd6d68f7ea57978 Parents: 5afdc68 Author: rawkintrevo <[email protected]> Authored: Fri Feb 24 07:37:06 2017 -0600 Committer: rawkintrevo <[email protected]> Committed: Fri Feb 24 07:37:06 2017 -0600 ---------------------------------------------------------------------- .../algorithms/RegressionTestsSuiteBase.scala | 22 ++++++++++++++++++++ 1 file changed, 22 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mahout/blob/ba37a8aa/math-scala/src/test/scala/org/apache/mahout/math/algorithms/RegressionTestsSuiteBase.scala ---------------------------------------------------------------------- diff --git a/math-scala/src/test/scala/org/apache/mahout/math/algorithms/RegressionTestsSuiteBase.scala b/math-scala/src/test/scala/org/apache/mahout/math/algorithms/RegressionTestsSuiteBase.scala index 1178a9b..55967e1 100644 --- a/math-scala/src/test/scala/org/apache/mahout/math/algorithms/RegressionTestsSuiteBase.scala +++ b/math-scala/src/test/scala/org/apache/mahout/math/algorithms/RegressionTestsSuiteBase.scala @@ -20,6 +20,7 @@ package org.apache.mahout.math.algorithms import org.apache.mahout.math.algorithms.regression.OrdinaryLeastSquares +import org.apache.mahout.math.algorithms.regression.tests._ import org.apache.mahout.math.drm.drmParallelize import org.apache.mahout.math.drm.RLikeDrmOps._ import org.apache.mahout.math.scalabindings.{`::`, dense} @@ -84,4 +85,25 @@ trait RegressionTestsSuiteBase extends DistributedMahoutSuite with Matchers { } + test("durbinWatsonTest test") { + /** + * R Prototype + * + * library(car) + * residuals <- seq(0, 4.9, 0.1) + * ## perform Durbin-Watson test + * durbinWatsonTest(residuals) + */ + + val correctAnswer = 0.001212121 + val err1 = drmParallelize( dense((0.0 until 5.0 by 0.1).toArray) ).t + val drmX = drmParallelize( dense((0 until 50).toArray.map( t => Math.pow(-1.0, t)) ) ).t + val drmY = drmX + err1 + 1 + var model = new OrdinaryLeastSquares[Int]().fit(drmX, drmY) + val syntheticResiduals = err1 + model = AutocorrelationTests.DurbinWatson(model, syntheticResiduals) + val myAnswer: Double = model.testResults.getOrElse('durbinWatsonTestStatistic, -1.0).asInstanceOf[Double] + (myAnswer - correctAnswer) should be < epsilon + } + }
