-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathIsolationForestTest.scala
31 lines (25 loc) · 1012 Bytes
/
IsolationForestTest.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
// Wei Chen - Isolation Forest Test
// 2022-03-05
import com.scalaml.TestData._
import com.scalaml.general.MatrixFunc._
import com.scalaml.algorithm.IsolationForest
import org.scalatest.funsuite.AnyFunSuite
class IsolationForestSuite extends AnyFunSuite {
val iforest = new IsolationForest()
test("IsolationForest Test : Clear") {
assert(iforest.clear())
}
test("IsolationForest Test : Abnormal Large Data") {
assert(iforest.clear())
assert(iforest.config(Map("tree_n" -> 100.0)))
assert(iforest.train(UNLABELED_LARGE_DATA))
val result = iforest.predict(UNLABELED_LARGE_DATA)
assert(arraysimilar(result, UNLABELED_LARGE_DATA.map(_ => 1.0), UNLABELED_NONLINEAR_DATA.size))
assert(result.last < result.sum / result.size)
}
test("IsolationForest Test : Invalid Data") {
assert(iforest.clear())
assert(!iforest.config(Map("maxLayer" -> "test")))
assert(!iforest.train(Array(Array(1, 2), Array())))
}
}