File: test_classif_probit.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 (37 lines) | stat: -rw-r--r-- 1,122 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
35
36
37
context("classif_probit")

test_that("classif_probit", {
  # suppressed warnings: "glm.fit: algorithm did not converge"
  # "glm.fit: fitted probabilities numerically 0 or 1 occurred"

  m = suppressWarnings(
    glm(formula = binaryclass.formula, data = binaryclass.train,
      family = binomial(link = "probit"))
  )

  p = predict(m, newdata = binaryclass.test, type = "response")
  p.prob = 1 - p
  p.class = as.factor(binaryclass.class.levs[ifelse(p > 0.5, 2, 1)])

  suppressWarnings(
    testSimple("classif.probit", binaryclass.df, binaryclass.target,
      binaryclass.train.inds, p.class)
  )
  suppressWarnings(
    testProb("classif.probit", binaryclass.df, binaryclass.target,
      binaryclass.train.inds, p.prob)
  )

  tt = function(formula, data) {
    glm(formula, data = data, family = binomial(link = "probit"))
  }
  tp = function(model, newdata) {
    p = predict(model, newdata, type = "response")
    as.factor(binaryclass.class.levs[ifelse(p > 0.5, 2, 1)])
  }

  suppressWarnings(
    testCV("classif.probit", binaryclass.df, binaryclass.target, tune.train = tt,
      tune.predict = tp)
  )
})