puSummaryThLoop: puSummaryThLoop

Description Usage Arguments Value Examples

View source: R/puSummaryThLoop.R

Description

An example for a PU summary function which derives the maximum performance metric over a set of thresholds. Here 50 thresholds between the medians of the positive and unlabeled hold out predictions.

Usage

1
2
puSummaryThLoop(data, lev = NULL, model = NULL, thresholds = NULL,
  maximize = c("puF", "puF1"), returnAll = FALSE, calcAUC = FALSE)

Arguments

data

a data frame or matrix with columns obs, pred, and pos. The first two are the binary observed, predicted outcomes and the latter one the continous outcome for the positive class.

lev

a character vector of factors levels for the response (default is NULL).

model

a character string for the model name (as taken form the method argument of train) (default is NULL).

thresholds

thresholds for which to calcualte the performance metrics

maximize

Charater (vector). The metrics to be maximized. Must correspond to a name of the vector returned by puSummary.

returnAll

return metrics for all thresholds.

Value

values of performance metrics

Examples

 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
## Not run: 
data(bananas)
tuneGrid <- expand.grid(sigma=c(1:10)*rep(c(.1, 1), each=10), 
                       nu=c(0.01, 0.05, 0.10, 0.15, 0.20, 0.25))
model <- trainOcc(x=bananas$tr[, -1], y=bananas$tr[, 1], 
                 method="ocsvm", tuneGrid=tuneGrid)
model <- update(model, aggregatePredictions=TRUE, 
               metric="puFAP")
model <- update(model, aggregatePredictions=TRUE, 
               puSummaryFunction = puSummaryThLoop, 
               metric="thPuFAP")
pairs(model$results[, c("puF", "puFAP", "thPuFAP")])

mp.puF <- modelPosition(model, modRank=1, by="puF")
mp.puFAP <- modelPosition(model, modRank=1, by="puFAP")
mp.thPuFAP <- modelPosition(model, modRank=1, by="thPuFAP")

featurespace(update(model, modRow=mp.puF$row))
featurespace(update(model, modRow=mp.puFAP$row))
featurespace(update(model, modRow=mp.thPuFAP$row))
pred.puF <- predict(update(model, modRow=mp.puF$row), 
                   bananas$x, returnRaster=FALSE)
pred.puFAP <- predict(update(model, modRow=mp.puFAP$row), 
                     bananas$x, returnRaster=FALSE)
pred.thPuFAP <- predict(update(model, modRow=mp.thPuFAP$row), 
                       bananas$x, returnRaster=FALSE)
hist(update(model, modRow=mp.puF$row), pred.puF)
hist(update(model, modRow=mp.puFAP$row), pred.puFAP)
hist(update(model, modRow=mp.thPuFAP$row), pred.thPuFAP)
abline(v=c(0, model$results[mp.thPuFAP$row, "thAP"] ))

## End(Not run)

benmack/oneClass documentation built on Dec. 15, 2020, 7:38 p.m.