-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
print.R
114 lines (109 loc) · 4.21 KB
/
print.R
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -------------------------------------------------------------------------------
# This file is part of Ranger.
#
# Ranger is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ranger is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ranger. If not, see <http://www.gnu.org/licenses/>.
#
# Written by:
#
# Marvin N. Wright
# Institut fuer Medizinische Biometrie und Statistik
# Universitaet zu Luebeck
# Ratzeburger Allee 160
# 23562 Luebeck
# Germany
#
# http://www.imbs-luebeck.de
# -------------------------------------------------------------------------------
##' Print contents of Ranger object.
##'
##'
##' @title Print Ranger
##' @param x Object of class 'ranger'.
##' @param ... Further arguments passed to or from other methods.
##' @seealso \code{\link{ranger}}
##' @author Marvin N. Wright
##' @export
print.ranger <- function(x, ...) {
cat("Ranger result\n\n")
cat("Call:\n", deparse(x$call), "\n\n")
cat("Type: ", x$treetype, "\n")
cat("Number of trees: ", x$num.trees, "\n")
cat("Sample size: ", x$num.samples, "\n")
cat("Number of independent variables: ", x$num.independent.variables, "\n")
cat("Mtry: ", x$mtry, "\n")
cat("Target node size: ", x$min.node.size, "\n")
cat("Variable importance mode: ", x$importance.mode, "\n")
cat("Splitrule: ", x$splitrule, "\n")
if (x$treetype == "Survival") {
cat("Number of unique death times: ", length(x$unique.death.times), "\n")
}
if (!is.null(x$splitrule) && x$splitrule == "extratrees" && !is.null(x$num.random.splits)) {
cat("Number of random splits: ", x$num.random.splits, "\n")
}
if (x$treetype == "Classification") {
cat("OOB prediction error: ", sprintf("%1.2f %%", 100*x$prediction.error), "\n")
} else if (x$treetype == "Regression") {
cat("OOB prediction error (MSE): ", x$prediction.error, "\n")
} else if (x$treetype == "Survival") {
cat("OOB prediction error (1-C): ", x$prediction.error, "\n")
} else if (x$treetype == "Probability estimation") {
cat("OOB prediction error (Brier s.): ", x$prediction.error, "\n")
} else {
cat("OOB prediction error: ", x$prediction.error, "\n")
}
if (x$treetype == "Regression") {
cat("R squared (OOB): ", x$r.squared, "\n")
}
}
##' Print contents of Ranger forest object.
##'
##'
##' @title Print Ranger forest
##' @param x Object of class 'ranger.forest'.
##' @param ... further arguments passed to or from other methods.
##' @author Marvin N. Wright
##' @export
print.ranger.forest <- function(x, ...) {
cat("Ranger forest object\n\n")
cat("Type: ", x$treetype, "\n")
cat("Number of trees: ", x$num.trees, "\n")
if (x$treetype == "Survival") {
cat("Number of unique death times: ", length(x$unique.death.times), "\n")
}
}
##' Print contents of Ranger prediction object.
##'
##'
##' @title Print Ranger prediction
##' @param x Object of class 'ranger.prediction'.
##' @param ... further arguments passed to or from other methods.
##' @author Marvin N. Wright
##' @export
print.ranger.prediction <- function(x, ...) {
cat("Ranger prediction\n\n")
cat("Type: ", x$treetype, "\n")
cat("Sample size: ", x$num.samples, "\n")
cat("Number of independent variables: ", x$num.independent.variables, "\n")
if (x$treetype == "Survival") {
cat("Number of unique death times: ", length(x$unique.death.times), "\n")
}
}
str.ranger.forest <- function(object, max.level = 2, ...) {
class(object) <- "list"
str(object, max.level = max.level, ...)
}
str.ranger <- function(object, max.level = 2, ...) {
class(object) <- "list"
str(object, max.level = max.level, ...)
}