File: c50.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 (43 lines) | stat: -rw-r--r-- 1,695 bytes parent folder | download | duplicates (3)
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
# c50.R: plotmo functions for model objects from the C50 package

plotmo.prolog.C5.0 <- function(object, object.name, trace, ...) # invoked when plotmo starts
{
    # "imp" is a vector of variable indices (column numbers in x), most
    # important vars first, no variables with relative.influence < 1%.
    imp <- order.C5.0.vars.on.importance(object)
    attr(object, "plotmo.importance") <- imp
    if(trace > 0)
        cat0("importance: ",
             paste.trunc(object$predictors[imp], maxlen=120), "\n")

    object
}
order.C5.0.vars.on.importance <- function(object)
{
    imp <- C50::C5imp(object)
    stopifnot(is.data.frame(imp) && all(dim(imp) == c(object$dims[2], 1)))
    imp <- imp[imp >= 1, , drop=FALSE]
    stopifnot(length(imp) > 0)
    imp <- match(rownames(imp), object$predictors)
    stopifnot(!anyNA(imp))
    imp
}
plotmo.singles.C5.0 <- function(object, x, nresponse, trace, all1, ...)
{
    if(all1)
        return(1:length(object$predictors))
    importance <- attr(object, "plotmo.importance")
    stopifnot(!is.null(importance)) # uninitialized?
    # indices of vars with importance >= 1%, max of 10 variables
    # (10 becauses plotmo.pairs returns 6, total is 16, therefore 4x4 grid)
    importance[1: min(10, length(importance))]
}
plotmo.pairs.C5.0 <- function(object, ...)
{
    importance <- attr(object, "plotmo.importance")
    stopifnot(!is.null(importance)) # uninitialized?
    # choose npairs so a total of no more than 16 plots
    # npairs=5 gives 10 pairplots, npairs=4 gives 6 pairplots
    npairs <- if(length(importance) <= 6) 5 else 4
    form.pairs(importance[1: min(npairs, length(importance))])
}