Learn R Programming

healthcareai (version 1.2.4)

findBestAlternateScenarios: Find most biggest drop in predictive probability across alternate features

Description

Compare each alternate probability prediction and determine which ones are lowest compared to the original; return the top three column names that lead to the biggest drop and their target value.

Usage

findBestAlternateScenarios(dfAlternateFeat, originalRow, predictionVector,
  predictionOriginal)

Arguments

dfAlternateFeat

Data frame of alternate feature values

originalRow

Row from original data frame upon which alternates are based

predictionVector

List of alternate predictions

predictionOriginal

Scalar representing original prediction for row, without alternative scenario

References

http://healthcareai-r.readthedocs.io

See Also

healthcareai

Examples

Run this code
# NOT RUN {
library(caret)
df <- data.frame(a = c(1,2,3,1),
                 b = c('m','f','m','m'),
                 c = c(0.7,1.4,2.4,2.0),
                 d = c(100,250,200,150))

y <- c('y','n','y','n')

dfAlt <- calculateSDChanges(df = df,
                            rowNum = 2,
                            sizeOfSDPerturb = 0.5,
                            numColLeaveOut = 'd')

glmOb <- train(x = df,y = y,method = 'glm',family = 'binomial')

originalPred <- predict(object = glmOb,
                        newdata = df[4,],
                        type = 'prob')

alternatePred <- calulcateAlternatePredictions(df = dfAlt,
                                               modelObj = glmOb,
                                               type = 'lasso',
                                               removeCols = 'AlteredCol')

dfResult <- findBestAlternateScenarios(dfAlternateFeat = dfAlt,
                                       originalRow = df[4,],
                                       predictionVector = as.numeric(alternatePred),
                                       predictionOriginal = originalPred[[2]])

dfResult
# }

Run the code above in your browser using DataLab