View source: R/30_CONFUSION_MATRIX.R
cutoff.palette | R Documentation |
cutoff.palette
returns confusion matrix along with accompanied performance metrics.
cutoff.palette(predictions, observed, min.pct.obs = 0.05, min.pct.def = 0.01)
predictions |
Model predictions. |
observed |
Observed values of target variable. |
min.pct.obs |
Minimum percentage of observations. Used to select boundaries of cutoff values. Default value is 0.05. |
min.pct.def |
Minimum percentage of default. Used to select boundaries of cutoff values. Default value is 0.01. |
The command cutoff.palette
returns data frame with minimum and maximum values of each confusion
matrix metric along with optimized cutoff itself.
suppressMessages(library(PDtoolkit))
data(loans)
#identify numeric risk factors
num.rf <- sapply(loans, is.numeric)
num.rf <- names(num.rf)[!names(num.rf)%in%"Creditability" & num.rf]
#discretized numeric risk factors using mdt.bin from monobin package
loans[, num.rf] <- sapply(num.rf, function(x)
mdt.bin(x = loans[, x], y = loans[, "Creditability"])[[2]])
str(loans)
res <- stepFWD(start.model = Creditability ~ 1,
p.value = 0.05,
coding = "WoE",
db = loans)
#run cutoff optimization
cop <- cutoff.palette(predictions = predict(res$model, type = "response"),
observed = loans$"Creditability",
min.pct.obs = 0.05,
min.pct.def = 0.01)
cop
confusion.matrix(predictions = predict(res$model, type = "response"),
observed = loans$"Creditability",
cutoff = cop$cutoff.max[cop$metric%in%"f1.score"])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.