| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/performance.R |
| 3 |
\name{performance} |
| 4 |
\alias{performance} |
| 5 |
\title{Function to create performance objects} |
| 6 |
\usage{ |
| 7 |
performance(prediction.obj, measure, x.measure = "cutoff", ...) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{prediction.obj}{An object of class \code{prediction}.} |
| 11 |
|
| 12 |
\item{measure}{Performance measure to use for the evaluation. A complete list |
| 13 |
of the performance measures that are available for \code{measure} and |
| 14 |
\code{x.measure} is given in the 'Details' section.} |
| 15 |
|
| 16 |
\item{x.measure}{A second performance measure. If different from the default, |
| 17 |
a two-dimensional curve, with \code{x.measure} taken to be the unit in |
| 18 |
direction of the x axis, and \code{measure} to be the unit in direction of |
| 19 |
the y axis, is created. This curve is parametrized with the cutoff.} |
| 20 |
|
| 21 |
\item{...}{Optional arguments (specific to individual performance measures).} |
| 22 |
} |
| 23 |
\value{ |
| 24 |
An S4 object of class \code{performance}. |
| 25 |
} |
| 26 |
\description{ |
| 27 |
All kinds of predictor evaluations are performed using this function. |
| 28 |
} |
| 29 |
\details{ |
| 30 |
Here is the list of available performance measures. Let Y and |
| 31 |
\eqn{\hat{Y}}{Yhat} be random variables representing the class and the prediction for |
| 32 |
a randomly drawn sample, respectively. We denote by |
| 33 |
\eqn{\oplus}{+} and \eqn{\ominus}{-} the positive and |
| 34 |
negative class, respectively. Further, we use the following |
| 35 |
abbreviations for empirical quantities: P (# positive |
| 36 |
samples), N (# negative samples), TP (# true positives), TN (# true |
| 37 |
negatives), FP (# false positives), FN (# false negatives). |
| 38 |
\describe{ |
| 39 |
\item{\code{acc}:}{Accuracy. \eqn{P(\hat{Y}=Y)}{P(Yhat = Y)}. Estimated |
| 40 |
as: \eqn{\frac{TP+TN}{P+N}}{(TP+TN)/(P+N)}.} |
| 41 |
\item{\code{err}:}{Error rate. \eqn{P(\hat{Y}\ne Y)}{P(Yhat != |
| 42 |
Y)}. Estimated as: \eqn{\frac{FP+FN}{P+N}}{(FP+FN)/(P+N)}.} |
| 43 |
\item{\code{fpr}:}{False positive rate. \eqn{P(\hat{Y}=\oplus | Y = |
| 44 |
\ominus)}{P(Yhat = + | Y = -)}. Estimated as: |
| 45 |
\eqn{\frac{FP}{N}}{FP/N}.} |
| 46 |
\item{\code{fall}:}{Fallout. Same as \code{fpr}.} |
| 47 |
\item{\code{tpr}:}{True positive |
| 48 |
rate. \eqn{P(\hat{Y}=\oplus|Y=\oplus)}{P(Yhat = + | Y = +)}. Estimated |
| 49 |
as: \eqn{\frac{TP}{P}}{TP/P}.} |
| 50 |
\item{\code{rec}:}{Recall. Same as \code{tpr}.} |
| 51 |
\item{\code{sens}:}{Sensitivity. Same as \code{tpr}.} |
| 52 |
\item{\code{fnr}:}{False negative |
| 53 |
rate. \eqn{P(\hat{Y}=\ominus|Y=\oplus)}{P(Yhat = - | Y = |
| 54 |
+)}. Estimated as: \eqn{\frac{FN}{P}}{FN/P}.} |
| 55 |
\item{\code{miss}:}{Miss. Same as \code{fnr}.} |
| 56 |
\item{\code{tnr}:}{True negative rate. \eqn{P(\hat{Y} = |
| 57 |
\ominus|Y=\ominus)}{P(Yhat = - | Y = -)}.} |
| 58 |
\item{\code{spec}:}{Specificity. Same as \code{tnr}.} |
| 59 |
\item{\code{ppv}:}{Positive predictive |
| 60 |
value. \eqn{P(Y=\oplus|\hat{Y}=\oplus)}{P(Y = + | Yhat = |
| 61 |
+)}. Estimated as: \eqn{\frac{TP}{TP+FP}}{TP/(TP+FP)}.} |
| 62 |
\item{\code{prec}:}{Precision. Same as \code{ppv}.} |
| 63 |
\item{\code{npv}:}{Negative predictive |
| 64 |
value. \eqn{P(Y=\ominus|\hat{Y}=\ominus)}{P(Y = - | Yhat = |
| 65 |
-)}. Estimated as: \eqn{\frac{TN}{TN+FN}}{TN/(TN+FN)}.} |
| 66 |
\item{\code{pcfall}:}{Prediction-conditioned |
| 67 |
fallout. \eqn{P(Y=\ominus|\hat{Y}=\oplus)}{P(Y = - | Yhat = |
| 68 |
+)}. Estimated as: \eqn{\frac{FP}{TP+FP}}{FP/(TP+FP)}.} |
| 69 |
\item{\code{pcmiss}:}{Prediction-conditioned |
| 70 |
miss. \eqn{P(Y=\oplus|\hat{Y}=\ominus)}{P(Y = + | Yhat = |
| 71 |
-)}. Estimated as: \eqn{\frac{FN}{TN+FN}}{FN/(TN+FN)}.} |
| 72 |
\item{\code{rpp}:}{Rate of positive predictions. \eqn{P( \hat{Y} = |
| 73 |
\oplus)}{P(Yhat = +)}. Estimated as: (TP+FP)/(TP+FP+TN+FN).} |
| 74 |
\item{\code{rnp}:}{Rate of negative predictions. \eqn{P( \hat{Y} = |
| 75 |
\ominus)}{P(Yhat = -)}. Estimated as: (TN+FN)/(TP+FP+TN+FN).} |
| 76 |
\item{\code{phi}:}{Phi correlation coefficient. \eqn{\frac{TP \cdot |
| 77 |
TN - FP \cdot FN}{\sqrt{ (TP+FN) \cdot (TN+FP) \cdot (TP+FP) |
| 78 |
\cdot (TN+FN)}}}{(TP*TN - |
| 79 |
FP*FN)/(sqrt((TP+FN)*(TN+FP)*(TP+FP)*(TN+FN)))}. Yields a |
| 80 |
number between -1 and 1, with 1 indicating a perfect |
| 81 |
prediction, 0 indicating a random prediction. Values below 0 |
| 82 |
indicate a worse than random prediction.} |
| 83 |
\item{\code{mat}:}{Matthews correlation coefficient. Same as \code{phi}.} |
| 84 |
\item{\code{mi}:}{Mutual information. \eqn{I(\hat{Y},Y) := H(Y) - |
| 85 |
H(Y|\hat{Y})}{I(Yhat, Y) := H(Y) - H(Y | Yhat)}, where H is the |
| 86 |
(conditional) entropy. Entropies are estimated naively (no bias |
| 87 |
correction).} |
| 88 |
\item{\code{chisq}:}{Chi square test statistic. \code{?chisq.test} |
| 89 |
for details. Note that R might raise a warning if the sample size |
| 90 |
is too small.} |
| 91 |
\item{\code{odds}:}{Odds ratio. \eqn{\frac{TP \cdot TN}{FN \cdot |
| 92 |
FP}}{(TP*TN)/(FN*FP)}. Note that odds ratio produces |
| 93 |
Inf or NA values for all cutoffs corresponding to FN=0 or |
| 94 |
FP=0. This can substantially decrease the plotted cutoff region.} |
| 95 |
\item{\code{lift}:}{Lift |
| 96 |
value. \eqn{\frac{P(\hat{Y}=\oplus|Y=\oplus)}{P(\hat{Y}=\oplus)}}{P(Yhat = + | |
| 97 |
Y = +)/P(Yhat = +)}.} |
| 98 |
\item{\code{f}:}{Precision-recall F measure (van Rijsbergen, 1979). Weighted |
| 99 |
harmonic mean of precision (P) and recall (R). \eqn{F = |
| 100 |
\frac{1}{\alpha \frac{1}{P} + (1-\alpha)\frac{1}{R}}}{F = 1/ |
| 101 |
(alpha*1/P + (1-alpha)*1/R)}. If |
| 102 |
\eqn{\alpha=\frac{1}{2}}{alpha=1/2}, the mean is balanced. A |
| 103 |
frequent equivalent formulation is |
| 104 |
\eqn{F = \frac{(\beta^2+1) \cdot P \cdot R}{R + \beta^2 \cdot |
| 105 |
P}}{F = (beta^2+1) * P * R / (R + beta^2 * P)}. In this formulation, the |
| 106 |
mean is balanced if \eqn{\beta=1}{beta=1}. Currently, ROCR only accepts |
| 107 |
the alpha version as input (e.g. \eqn{\alpha=0.5}{alpha=0.5}). If no |
| 108 |
value for alpha is given, the mean will be balanced by default.} |
| 109 |
\item{\code{rch}:}{ROC convex hull. A ROC (=\code{tpr} vs \code{fpr}) curve |
| 110 |
with concavities (which represent suboptimal choices of cutoff) removed |
| 111 |
(Fawcett 2001). Since the result is already a parametric performance |
| 112 |
curve, it cannot be used in combination with other measures.} |
| 113 |
\item{\code{auc}:}{Area under the ROC curve. This is equal to the value of the |
| 114 |
Wilcoxon-Mann-Whitney test statistic and also the probability that the |
| 115 |
classifier will score are randomly drawn positive sample higher than a |
| 116 |
randomly drawn negative sample. Since the output of |
| 117 |
\code{auc} is cutoff-independent, this |
| 118 |
measure cannot be combined with other measures into a parametric |
| 119 |
curve. The partial area under the ROC curve up to a given false |
| 120 |
positive rate can be calculated by passing the optional parameter |
| 121 |
\code{fpr.stop=0.5} (or any other value between 0 and 1) to |
| 122 |
\code{performance}.} |
| 123 |
\item{\code{aucpr}:}{Area under the Precision/Recall curve. Since the output |
| 124 |
of \code{aucpr} is cutoff-independent, this measure cannot be combined |
| 125 |
with other measures into a parametric curve.} |
| 126 |
\item{\code{prbe}:}{Precision-recall break-even point. The cutoff(s) where |
| 127 |
precision and recall are equal. At this point, positive and negative |
| 128 |
predictions are made at the same rate as their prevalence in the |
| 129 |
data. Since the output of |
| 130 |
\code{prbe} is just a cutoff-independent scalar, this |
| 131 |
measure cannot be combined with other measures into a parametric curve.} |
| 132 |
\item{\code{cal}:}{Calibration error. The calibration error is the |
| 133 |
absolute difference between predicted confidence and actual reliability. This |
| 134 |
error is estimated at all cutoffs by sliding a window across the |
| 135 |
range of possible cutoffs. The default window size of 100 can be |
| 136 |
adjusted by passing the optional parameter \code{window.size=200} |
| 137 |
to \code{performance}. E.g., if for several |
| 138 |
positive samples the output of the classifier is around 0.75, you might |
| 139 |
expect from a well-calibrated classifier that the fraction of them |
| 140 |
which is correctly predicted as positive is also around 0.75. In a |
| 141 |
well-calibrated classifier, the probabilistic confidence estimates |
| 142 |
are realistic. Only for use with |
| 143 |
probabilistic output (i.e. scores between 0 and 1).} |
| 144 |
\item{\code{mxe}:}{Mean cross-entropy. Only for use with |
| 145 |
probabilistic output. \eqn{MXE :=-\frac{1}{P+N}( \sum_{y_i=\oplus} |
| 146 |
ln(\hat{y}_i) + \sum_{y_i=\ominus} ln(1-\hat{y}_i))}{MXE := - 1/(P+N) \sum_{y_i=+} |
| 147 |
ln(yhat_i) + \sum_{y_i=-} ln(1-yhat_i)}. Since the output of |
| 148 |
\code{mxe} is just a cutoff-independent scalar, this |
| 149 |
measure cannot be combined with other measures into a parametric curve.} |
| 150 |
\item{\code{rmse}:}{Root-mean-squared error. Only for use with |
| 151 |
numerical class labels. \eqn{RMSE:=\sqrt{\frac{1}{P+N}\sum_i (y_i |
| 152 |
- \hat{y}_i)^2}}{RMSE := sqrt(1/(P+N) \sum_i (y_i - |
| 153 |
yhat_i)^2)}. Since the output of |
| 154 |
\code{rmse} is just a cutoff-independent scalar, this |
| 155 |
measure cannot be combined with other measures into a parametric curve.} |
| 156 |
\item{\code{sar}:}{Score combinining performance measures of different |
| 157 |
characteristics, in the attempt of creating a more "robust" |
| 158 |
measure (cf. Caruana R., ROCAI2004): |
| 159 |
SAR = 1/3 * ( Accuracy + Area under the ROC curve + Root |
| 160 |
mean-squared error ).} |
| 161 |
\item{\code{ecost}:}{Expected cost. For details on cost curves, |
| 162 |
cf. Drummond&Holte 2000,2004. \code{ecost} has an obligatory x |
| 163 |
axis, the so-called 'probability-cost function'; thus it cannot be |
| 164 |
combined with other measures. While using \code{ecost} one is |
| 165 |
interested in the lower envelope of a set of lines, it might be |
| 166 |
instructive to plot the whole set of lines in addition to the lower |
| 167 |
envelope. An example is given in \code{demo(ROCR)}.} |
| 168 |
\item{\code{cost}:}{Cost of a classifier when |
| 169 |
class-conditional misclassification costs are explicitly given. |
| 170 |
Accepts the optional parameters \code{cost.fp} and |
| 171 |
\code{cost.fn}, by which the costs for false positives and |
| 172 |
negatives can be adjusted, respectively. By default, both are set |
| 173 |
to 1.} |
| 174 |
} |
| 175 |
} |
| 176 |
\note{ |
| 177 |
Here is how to call \code{performance()} to create some standard |
| 178 |
evaluation plots: |
| 179 |
\describe{ |
| 180 |
\item{ROC curves:}{measure="tpr", x.measure="fpr".} |
| 181 |
\item{Precision/recall graphs:}{measure="prec", x.measure="rec".} |
| 182 |
\item{Sensitivity/specificity plots:}{measure="sens", x.measure="spec".} |
| 183 |
\item{Lift charts:}{measure="lift", x.measure="rpp".} |
| 184 |
} |
| 185 |
} |
| 186 |
\examples{ |
| 187 |
# computing a simple ROC curve (x-axis: fpr, y-axis: tpr) |
| 188 |
library(ROCR) |
| 189 |
data(ROCR.simple) |
| 190 |
pred <- prediction( ROCR.simple$predictions, ROCR.simple$labels) |
| 191 |
pred |
| 192 |
perf <- performance(pred,"tpr","fpr") |
| 193 |
perf |
| 194 |
plot(perf) |
| 195 |
|
| 196 |
# precision/recall curve (x-axis: recall, y-axis: precision) |
| 197 |
perf <- performance(pred, "prec", "rec") |
| 198 |
perf |
| 199 |
plot(perf) |
| 200 |
|
| 201 |
# sensitivity/specificity curve (x-axis: specificity, |
| 202 |
# y-axis: sensitivity) |
| 203 |
perf <- performance(pred, "sens", "spec") |
| 204 |
perf |
| 205 |
plot(perf) |
| 206 |
} |
| 207 |
\references{ |
| 208 |
A detailed list of references can be found on the ROCR homepage at |
| 209 |
\url{https://ipa-tys.github.io/ROCR/}. |
| 210 |
} |
| 211 |
\seealso{ |
| 212 |
\code{\link{prediction}}, |
| 213 |
\code{\link{prediction-class}}, |
| 214 |
\code{\link{performance-class}}, |
| 215 |
\code{\link{plot.performance}} |
| 216 |
} |
| 217 |
\author{ |
| 218 |
Tobias Sing \email{[email protected]}, Oliver Sander |
| 219 |
\email{[email protected]} |
| 220 |
} |