caret (version 5.02-011)

lift: Lift Plot

Description

For classification models, this function creates a 'lift plot' that describes how well a model ranks samples for one class

Usage

lift(x, data = NULL, class = NULL, cuts = 11, 
     subset = TRUE, lattice.options = NULL, ...)

Arguments

x
a lattice formula (see xyplot for syntax) where the left-hand side of the formula is a factor class variable of the observed outcome and the right-hand side specifies one or model
data
a data frame (or more precisely, anything that is a valid envir argument in veal, e.g., a list or an environment) containing values for any variables in the formula, as well as groups and subset if appli
class
a character string for the class of interest
cuts
the number of splits of the data are used to create the plot.
subset
An expression that evaluates to a logical or integer indexing vector. It is evaluated in data. Only the resulting rows of data are used for the plot.
lattice.options
A list that could be supplied to lattice.options
...
options to pass through to xyplot or the panel function

Value

  • a lattice object

Details

To construct the lift plot, the following steps are used for each model:

  1. The data are ordered by the numeric model prediction used on the right-hand side of the model formula
  2. The data are split intocuts - 1roughly equal groups
  3. the number of samples with true results equal toclassare determined
  4. the lift is calculated as the ratio of the percentage of samples in each split corresponding toclassover the same percentage in the entire data set
lift produces a plot of the cumulative lift values by the percentage of samples evaluated.

This implementation uses the lattice function xyplot, so plot elements can be changed via panel functions, trellis.par.set or other means.

See Also

xyplot, trellis.par.set

Examples

Run this code
panel.lift <- function(x,  y, ...)
{
  panel.xyplot(x, y, ...)
  panel.abline(0, 1, col = "black")  
}

set.seed(1)
simulated <- data.frame(obs = factor(rep(letters[1:2], each = 100)),
                        perfect = sort(runif(200), decreasing = TRUE),
                        random = runif(200))

lift(obs ~ random, data = simulated)
lift(obs ~ random, data = simulated, 
     panel = panel.lift, type = c("p", "l"))
lift(obs ~ random + perfect, data = simulated,
     panel = panel.lift, type = c("p", "l"),
     auto.key = list(columns = 2))

Run the code above in your browser using DataCamp Workspace