File: caret.R

package info (click to toggle)
r-cran-plotmo 3.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,400 kB
  • sloc: sh: 13; makefile: 2
file content (90 lines) | stat: -rw-r--r-- 3,328 bytes parent folder | download | duplicates (4)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# caret.R: plotmo functions for caret objects
#
# TODO Currently only caret "train" objects have explicit support.

# sanity check that object a caret train object
# (since "train" is a quite generic name)
check.is.caret.train.object <- function(object)
{
    class <- class(object)[1]
    stopifnot.string(class)
    mod <- object[["finalModel"]]
    # S3 models are lists, S4 models aren't lists.
    # Plotmo support S4 models only if they are wrapped in a caret model.
    # Example S4 model: kernlab::ksvm created with train(..., method="svmRadial", ...).
    if(class != "train" || is.null(mod) || (!is.list(mod) && !isS4(mod)))
        stop0("unrecognized \"train\" object ",
              "(was expecting a train object from the caret package)")
}
plotmo.prolog.train <- function(object, object.name, trace, ...)
{
    check.is.caret.train.object(object)
    # call plotmo.prolog for the finalModel for its side effects
    # (e.g. may attach plotmo.importance to the finalModel)
    finalModel <- try(plotmo.prolog(object$finalModel, object.name, trace, ...),
                      silent=trace < 2)
    is.err <- is.try.err(finalModel)
    trace1(trace, "plotmo.prolog(object$finalModel) %s\n",
           if(is.err) "failed, continuing anyway" else "succeeded (caret model)")
    if(!is.err)
        object$finalModel <- finalModel
    object
}
plotmo.singles.train <- function(object, x, nresponse, trace, all1, ...)
{
    check.is.caret.train.object(object)
    singles <- try(plotmo.singles(object$finalModel, x, nresponse, trace, all1, ...),
                   silent=trace < 2)
    is.err <- is.try.err(singles)
    trace2(trace, "plotmo.singles(object$finalModel) %s\n",
           if(is.err) "failed" else "succeeded")
    if(is.err)
        plotmo.singles.default(object, x, nresponse, trace, all1, ...)
    else
        singles
}
plotmo.pairs.train <- function(object, x, nresponse, trace, all2, ...)
{
    check.is.caret.train.object(object)
    pairs <- try(plotmo.pairs(object$finalModel, x, nresponse, trace, all2, ...),
                 silent=trace < 2)
    is.err <- is.try.err(pairs)
    trace2(trace, "plotmo.pairs(object$finalModel) %s\n",
           if(is.err) "failed" else "succeeded")
    if(is.err)
        plotmo.pairs.default(object, x, nresponse, trace, all2, ...)
    else
        pairs
}
# determine "type" arg for predict()
plotmo.type.train <- function(object, ..., TRACE)
{
    "raw"

    # check.is.caret.train.object(object)
    # trace <- TRACE
    # type <- try(plotmo.type(object$finalModel, ..., TRACE=TRACE), silent=trace < 2)
    # is.err <- is.try.err(type)
    # trace2(trace, "plotmo.type(object$finalModel) %s\n",
    #        if(is.err) "failed" else "succeeded")
    # if(is.err)
    #     "raw"
    # else
    #     type
}
# determine "type" arg for residuals()
plotmo.residtype.train <- function(object, ..., TRACE)
{
    "raw"

    # check.is.caret.train.object(object)
    # trace <- TRACE
    # type <- try(plotmo.residtype(object$finalModel, ...), silent=trace < 2)
    # is.err <- is.try.err(type)
    # trace2(trace, "plotmo.residtype(object$finalModel) %s\n",
    #        if(is.err) "failed" else "succeeded")
    # if(is.err)
    #     "raw"
    # else
    #     type
}