forked from Wei-1/Scala-Machine-Learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultivariateLinearRegressionTest.scala
39 lines (32 loc) · 1.45 KB
/
MultivariateLinearRegressionTest.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Wei Chen - Multivariate Linear Regression Test
// 2016-06-04
import com.scalaml.TestData._
import com.scalaml.general.MatrixFunc._
import com.scalaml.algorithm.MultivariateLinearRegression
import org.scalatest.funsuite.AnyFunSuite
class MultivariateLinearRegressionSuite extends AnyFunSuite {
val mlr = new MultivariateLinearRegression()
test("MultivariateLinearRegression Test : Clear") {
assert(mlr.clear())
}
test("MultivariateLinearRegression Test : Linear Data") {
assert(mlr.clear())
assert(mlr.config(Map[String, Double]()))
assert(mlr.train(LABELED_LINEAR_DATA.map(yx => yx._1.toDouble -> yx._2)))
val result = mlr.predict(UNLABELED_LINEAR_DATA)
val nResult = result.map(v => if (v > 0) 1.0 else -1.0)
assert(arraysimilar(nResult, LABEL_LINEAR_DATA.map(_.toDouble), 0.9))
}
test("MultivariateLinearRegression Test : Nonlinear Data - WRONG") {
assert(mlr.clear())
assert(mlr.config(Map[String, Double]()))
assert(mlr.train(LABELED_NONLINEAR_DATA.map(yx => yx._1.toDouble -> yx._2)))
val result = mlr.predict(UNLABELED_NONLINEAR_DATA)
assert(!arraysimilar(result, LABEL_NONLINEAR_DATA.map(_.toDouble), 0.45))
}
test("MultivariateLinearRegression Test : Invalid Config & Data") {
assert(mlr.clear())
assert(!mlr.config(Map("limit" -> "test")))
assert(!mlr.train(Array((1, Array(1, 2)), (1, Array()))))
}
}