Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

plotClassProbs

Plot Predicted Probabilities in Classification Models


Description

This function takes an object (preferably from the function extractProb) and creates a lattice plot.

Usage

plotClassProbs(object, plotType = "histogram", useObjects = FALSE, ...)

Arguments

object

an object (preferably from the function extractProb. There should be columns for each level of the class factor and columns named obs, pred, model (e.g. "rpart", "nnet" etc), dataType (e.g. "Training", "Test" etc) and optionally objects (for giving names to objects with the same model type).

plotType

either "histogram" or "densityplot"

useObjects

a logical; should the object name (if any) be used as a conditioning variable?

...

parameters to pass to histogram or densityplot

Details

If the call to extractProb included test data, these data are shown, but if unknowns were also included, these are not plotted

Value

A lattice object. Note that the plot has to be printed to be displayed (especially in a loop).

Author(s)

Max Kuhn

Examples

## Not run: 
data(mdrr)
set.seed(90)
inTrain <- createDataPartition(mdrrClass, p = .5)[[1]]

trainData <- mdrrDescr[inTrain,1:20]
testData <- mdrrDescr[-inTrain,1:20]

trainY <- mdrrClass[inTrain]
testY <- mdrrClass[-inTrain]

ctrl <- trainControl(method = "cv")

nbFit1 <- train(trainData, trainY, "nb",
                trControl = ctrl,
                tuneGrid = data.frame(usekernel = TRUE, fL = 0))

nbFit2 <- train(trainData, trainY, "nb",
                trControl = ctrl,
                tuneGrid = data.frame(usekernel = FALSE, fL = 0))


models <- list(para = nbFit2, nonpara = nbFit1)

predProbs <- extractProb(models, testX = testData,  testY = testY)

plotClassProbs(predProbs, useObjects = TRUE)
plotClassProbs(predProbs,
               subset = object == "para" & dataType == "Test")
plotClassProbs(predProbs,
               useObjects = TRUE,
               plotType = "densityplot",
               auto.key = list(columns = 2))

## End(Not run)

caret

Classification and Regression Training

v6.0-86
GPL (>= 2)
Authors
Max Kuhn [aut, cre], Jed Wing [ctb], Steve Weston [ctb], Andre Williams [ctb], Chris Keefer [ctb], Allan Engelhardt [ctb], Tony Cooper [ctb], Zachary Mayer [ctb], Brenton Kenkel [ctb], R Core Team [ctb], Michael Benesty [ctb], Reynald Lescarbeau [ctb], Andrew Ziem [ctb], Luca Scrucca [ctb], Yuan Tang [ctb], Can Candan [ctb], Tyler Hunt [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.