modelPerformance: Evaluate the performance of a model

Description Usage Arguments Value See Also Examples

View source: R/modelPerformance.R

Description

modelPerformance is a wrapper function that runs various model evaluation techniques and returns the results in a convenient list object. Parameters prefaced with a function dot (i.e. gainsChartDT.) are only applicable to the use of that function.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
modelPerformance(y, yhat, y2 = NULL, v = NULL, numBins = 10,
  gainsChartDT.scoreFormatType = "int", gainsChartDT.scoreFormatDigits = 5,
  gainsChartDT.contSumFormatType = "dlr",
  gainsChartDT.contSumFormatDigits = 0,
  gainsChartDT.contAvgFormatType = "dlr",
  gainsChartDT.contAvgFormatDigits = 0, gainsChartDT.KScolor = "#FF3005",
  gainsChartBarGraph.cb = "#009DDC", gainsChartBarGraph.cv = "#77BF30",
  gainsChartBarGraph.xLabel = "Model Quantile",
  gainsChartBarGraph.yLabel = "Mean Outcome",
  gainsChartBarGraph.yType = ifelse(is.null(y2), "pct", "dlr"),
  gainsChartBarGraph.yDigits = ifelse(is.null(y2), 1, 0),
  gainsChartPerfCurve.cb = "#009DDC", gainsChartPerfCurve.cv = "#77BF30",
  gainsChartPerfCurve.cr = "#666666",
  gainsChartPerfCurve.xLabel = "Cumulative Total Percent",
  gainsChartPerfCurve.yLabel = "Cumulative Outcome Percent",
  variableImportanceGraph.x = NULL, variableImportanceGraph.y = NULL,
  variableImportanceGraph.sumYcheck = TRUE,
  variableImportanceGraph.barColor = "rgba(0, 55, 82, 0.6)",
  variableImportanceGraph.lineColor = "#003752",
  variableImportanceGraph.lineWidth = 2)

Arguments

y

logical, integer or numeric vector (dependent variable)

yhat

numeric vector (predicted values of y)

y2

logical, integer or numeric vector (other dependent variable for combined models)

v

logical, integer or numeric vector of binary values (distinguishes validate (TRUE) vs. build (FALSE) observations)

numBins

integer value >= 2; number of desired bins

gainsChartDT.scoreFormatType

character string; format type for score field(s); valid values are "int", "dlr" and "pct"

gainsChartDT.scoreFormatDigits

non-negative integer value; number of decimal places for score field(s)

gainsChartDT.contSumFormatType

character string; format type for continuous sum field(s); valid values are "int", "dlr" and "pct"

gainsChartDT.contSumFormatDigits

non-negative integer value; number of decimal places for continuous sum field(s)

gainsChartDT.contAvgFormatType

character string; format type for continuous average (mean) field(s); valid values are "int", "dlr" and "pct"

gainsChartDT.contAvgFormatDigits

non-negative integer value; number of decimal places for continuous average (mean) field(s)

gainsChartDT.KScolor

character string; text color for max KS value (valid color)

gainsChartBarGraph.cb

character string; fill color for build bars (valid color)

gainsChartBarGraph.cv

character string; fill color for validate bars (valid color)

gainsChartBarGraph.xLabel

character string; x-axis label

gainsChartBarGraph.yLabel

character string; y-axis label

gainsChartBarGraph.yType

character string; y-axis format type; valid values are "int", "dlr" and "pct"

gainsChartBarGraph.yDigits

non-negative integer value indicating the number of decimal places to show when hovering over the bars

gainsChartPerfCurve.cb

character string; line color for build (valid color)

gainsChartPerfCurve.cv

character string; line color for validate (valid color)

gainsChartPerfCurve.cr

character string; random/reference line color (valid color)

gainsChartPerfCurve.xLabel

character string; x-axis label

gainsChartPerfCurve.yLabel

character string; y-axis label

variableImportanceGraph.x

character vector

variableImportanceGraph.y

numeric vector

variableImportanceGraph.sumYcheck

logical value; check that sum(y) == 1?

variableImportanceGraph.barColor

character string; fill color for bars (valid color)

variableImportanceGraph.lineColor

character string; line color (valid color)

variableImportanceGraph.lineWidth

non-negative integer value indicating line width (use 0 to omit)

Value

A named list with class mt_modelPerformance containing the following objects. Note that when v is supplied, the data will be split into build and validate sets where each set will be evaluated. When v is not supplied, the data is assumed to just be the "build" set.

See Also

gainsChart, gainsChartDT, gainsChartBarGraph, gainsChartPerfCurve, variableImportanceGraph

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# pull in sample scored data frame
x <- modelSampleScored
head(x)
# binary target
z <- modelPerformance(
    y = x$TargetFlag,
    yhat = x$pTargetFlag,
    v = x$ValidateFlag
)
class(z)
names(z)
names(z$build)
names(z$validate)
names(z$both)
z$validate$gcDT
z$both$gcBG
z$both$gcPC
# continuous target
z <- modelPerformance(
    y = x[x$TargetFlag, ]$TargetValue,
    yhat = x[x$TargetFlag, ]$pTargetValue,
    v = x[x$TargetFlag, ]$ValidateFlag,
    gainsChartBarGraph.yType = "dlr",
    gainsChartBarGraph.yDigits = 0
)
class(z)
names(z)
names(z$build)
names(z$validate)
names(z$both)
z$validate$gcDT
z$both$gcBG
z$both$gcPC
# combined target (with arbitrary variable importance parms)
z <- modelPerformance(
    y = x$TargetFlag,
    yhat = x$pTargetFlag*x$pTargetValue,
    y2 = x$TargetValue,
    v = x$ValidateFlag,
    variableImportanceGraph.x = c(
        "Days Since Last Transaction",
        "Average Order Value",
        "Signed Up Online",
        "Number of Transactions",
        "Tenure",
        "Multi-Category Flag"
    ),
    variableImportanceGraph.y = c(.18, .4, .04, .25, .12, .01)
)
class(z)
names(z)
names(z$build)
names(z$validate)
names(z$both)
z$validate$gcDT
z$both$gcBG
z$both$gcPC
z$varImp

dnegrey/miscTools documentation built on May 3, 2019, 2:57 p.m.