confusion.matrix: Confusion matrix

View source: R/30_CONFUSION_MATRIX.R

confusion.matrixR Documentation

Confusion matrix

Description

confusion.matrix returns confusion matrix along with accompanied performance metrics.

Usage

confusion.matrix(predictions, observed, cutoff)

Arguments

predictions

Model predictions.

observed

Observed values of target variable.

cutoff

Cutoff value. Single value numeric vector between 0 and 1.

Value

The command confusion.matrix returns list of two objects. The first object is confusion matrix table, while the second one is data frame with accompanied performance metrics.

Examples

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)
names(res)
summary(res$model)$coefficients
loans$model.pred <- predict(res$model, type = "response")
#confusion matrix
confusion.matrix(predictions = predict(res$model, type = "response"), 
	     observed = loans$"Creditability",
	     cutoff = 0.5)

PDtoolkit documentation built on Sept. 20, 2023, 9:06 a.m.