File: setThreshold.Rd

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 (48 lines) | stat: -rw-r--r-- 1,873 bytes parent folder | download | duplicates (4)
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
40
41
42
43
44
45
46
47
48
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/setThreshold.R
\name{setThreshold}
\alias{setThreshold}
\title{Set threshold of prediction object.}
\usage{
setThreshold(pred, threshold)
}
\arguments{
\item{pred}{(\link{Prediction})\cr
Prediction object.}

\item{threshold}{(\link{numeric})\cr
Threshold to produce class labels. Has to be a named vector, where names correspond to class labels.
Only for binary classification it can be a single numerical threshold for the positive class.}
}
\value{
(\link{Prediction}) with changed threshold and corresponding response.
}
\description{
Set threshold of prediction object for classification or multilabel classification.
Creates corresponding discrete class response for the newly set threshold.
For binary classification: The positive class is predicted if the probability value exceeds the threshold.
For multiclass: Probabilities are divided by corresponding thresholds and the class with maximum resulting value is selected.
The result of both are equivalent if in the multi-threshold case the values are greater than 0 and sum to 1.
For multilabel classification: A label is predicted (with entry \code{TRUE}) if a probability matrix entry
exceeds the threshold of the corresponding label.
}
\examples{
# create task and train learner (LDA)
task = makeClassifTask(data = iris, target = "Species")
lrn = makeLearner("classif.lda", predict.type = "prob")
mod = train(lrn, task)

# predict probabilities and compute performance
pred = predict(mod, newdata = iris)
performance(pred, measures = mmce)
head(as.data.frame(pred))

# adjust threshold and predict probabilities again
threshold = c(setosa = 0.4, versicolor = 0.3, virginica = 0.3)
pred = setThreshold(pred, threshold = threshold)
performance(pred, measures = mmce)
head(as.data.frame(pred))
}
\seealso{
\link{predict.WrappedModel}
}