-
Notifications
You must be signed in to change notification settings - Fork 9
/
OneHotTest.scala
39 lines (33 loc) · 1.23 KB
/
OneHotTest.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 - OneHot
// 2018-11-08
import com.scalaml.algorithm.OneHot
import org.scalatest.funsuite.AnyFunSuite
class OneHotSuite extends AnyFunSuite {
val table = Array(("key", "category"), ("value", "number"))
val data = Array(Array("A", "1.1"), Array("B", "1.2"))
val result = Array(Array(0.0, 1.0, 2.1), Array(1.0, 0.0, 2.2))
val oh = new OneHot(table)
test("OneHot Test : Encode") {
val encodeData = oh.encode(data)
assert(encodeData.head(0) == 1.0)
assert(encodeData.head(1) == 0.0)
assert(encodeData.head(2) == 1.1)
assert(encodeData.last(0) == 0.0)
assert(encodeData.last(1) == 1.0)
assert(encodeData.last(2) == 1.2)
}
test("OneHot Test : Decode") {
val decodeData = oh.decode(result)
Array(Array("B", "2.1"), Array("A", "2.2"))
assert(decodeData.head(0) == "B")
assert(decodeData.head(1) == "2.1")
assert(decodeData.last(0) == "A")
assert(decodeData.last(1) == "2.2")
}
test("OneHot Test : Invalid Data") {
assert(oh.encode(Array()) == null)
assert(oh.decode(Array()) == null)
assert(oh.encode(Array(Array())) == null)
assert(oh.decode(Array(Array())) == null)
}
}