File: checkPrediction.R

package info (click to toggle)
r-cran-mlr 2.19.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,264 kB
  • sloc: ansic: 65; sh: 13; makefile: 5
file content (25 lines) | stat: -rw-r--r-- 1,031 bytes parent folder | download | duplicates (3)
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
checkPrediction = function(pred, task.type = NULL, binary = FALSE, predict.type = NULL, check.truth = FALSE, no.na = TRUE) {
  assertClass(pred, "Prediction")
  if (!is.null(task.type) && pred$task.desc$type %nin% task.type) {
    stopf("Prediction must be one of '%s', but is: '%s'", collapse(task.type), pred$task.desc$type)
  }
  if (binary) {
    nlevs = length(pred$task.desc$class.levels)
    if (nlevs != 2L) {
      stopf("Prediction must be for binary classification, but has %i class levels!", nlevs)
    }
  }
  if (!is.null(predict.type) && pred$predict.type %nin% predict.type) {
    stopf("predict.type must be one of '%s', but is: '%s'", collapse(predict.type), pred$predict.type)
  }
  if (check.truth && is.null(pred$data$truth)) {
    stopf("Prediction object does not contain ground truth column 'truth'!")
  }

  if (no.na) {
    r = getPredictionResponse(pred)
    if (anyMissing(r)) {
      stopf("Prediction object contains NAs in response, this likely due to a prediction from a FailureModel!")
    }
  }
}