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

plotObsVsPred

Plot Observed versus Predicted Results in Regression and Classification Models


Description

This function takes an object (preferably from the function extractPrediction) and creates a lattice plot. For numeric outcomes, the observed and predicted data are plotted with a 45 degree reference line and a smoothed fit. For factor outcomes, a dotplot plot is produced with the accuracies for the different models.

Usage

plotObsVsPred(object, equalRanges = TRUE, ...)

Arguments

object

an object (preferably from the function extractPrediction. There should be columns named obs, pred, model (e.g. "rpart", "nnet" etc.) and dataType (e.g. "Training", "Test" etc)

equalRanges

a logical; should the x- and y-axis ranges be the same?

...

parameters to pass to xyplot or dotplot, such as auto.key

Details

If the call to extractPrediction included test data, these data are shown, but if unknowns were also included, they 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: 
# regression example
data(BostonHousing)
rpartFit <- train(BostonHousing[1:100, -c(4, 14)], 
                  BostonHousing$medv[1:100], 
                  "rpart", tuneLength = 9)
plsFit <- train(BostonHousing[1:100, -c(4, 14)], 
                BostonHousing$medv[1:100], 
                "pls")

predVals <- extractPrediction(list(rpartFit, plsFit), 
                              testX = BostonHousing[101:200, -c(4, 14)], 
                              testY = BostonHousing$medv[101:200], 
                              unkX = BostonHousing[201:300, -c(4, 14)])

plotObsVsPred(predVals)


#classification example
data(Satellite)
numSamples <- dim(Satellite)[1]
set.seed(716)

varIndex <- 1:numSamples

trainSamples <- sample(varIndex, 150)

varIndex <- (1:numSamples)[-trainSamples]
testSamples <- sample(varIndex, 100)

varIndex <- (1:numSamples)[-c(testSamples, trainSamples)]
unkSamples <- sample(varIndex, 50)

trainX <- Satellite[trainSamples, -37]
trainY <- Satellite[trainSamples, 37]

testX <- Satellite[testSamples, -37]
testY <- Satellite[testSamples, 37]

unkX <- Satellite[unkSamples, -37]

knnFit  <- train(trainX, trainY, "knn")
rpartFit <- train(trainX, trainY, "rpart")

predTargets <- extractPrediction(list(knnFit, rpartFit), 
                                 testX = testX, 
                                 testY = testY, 
                                 unkX = unkX)

plotObsVsPred(predTargets)

## 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.