File: test_classif_mlp.R

package info (click to toggle)
r-cran-mlr 2.18.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 7,088 kB
  • sloc: ansic: 65; sh: 13; makefile: 2
file content (34 lines) | stat: -rw-r--r-- 1,261 bytes parent folder | download
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
context("classif_mlp")

test_that("classif_mlp", {
  requirePackagesOrSkip("RSNNS", default.method = "load")

  # test with empty paramset
  capture.output({
    # neuralnet is not dealing with formula with `.` well
    x = data.matrix(binaryclass.train[, -ncol(binaryclass.train)])
    y = RSNNS::decodeClassLabels(binaryclass.train[, ncol(binaryclass.train)])
    m = RSNNS::mlp(x = x, y = y)
    p = predict(m, data.matrix(binaryclass.test[, -ncol(binaryclass.test)]))
    p = max.col(p)
    p = factor(p, labels = binaryclass.class.levs)
  })

  testSimple("classif.mlp", binaryclass.df, binaryclass.target,
    binaryclass.train.inds, p, parset = list())

  # test with params passed
  capture.output({
    # neuralnet is not dealing with formula with `.` well
    x = data.matrix(binaryclass.train[, -ncol(binaryclass.train)])
    y = RSNNS::decodeClassLabels(binaryclass.train[, ncol(binaryclass.train)])
    m = RSNNS::mlp(x = x, y = y, size = 7, maxit = 100)
    p = predict(m, data.matrix(binaryclass.test[, -ncol(binaryclass.test)]))
    p = max.col(p)
    p = factor(p, labels = binaryclass.class.levs)
  })

  testSimple("classif.mlp", binaryclass.df, binaryclass.target,
    binaryclass.train.inds, p,
    parset = list(size = 7, maxit = 100))
})