Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Predict with training quantiles by default #668

Merged
merged 2 commits into from May 13, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 11 additions & 6 deletions r-package/grf/R/quantile_forest.R
Expand Up @@ -148,7 +148,8 @@ quantile_forest <- function(X, Y,
#' Xi using only trees that did not use the i-th training example). Note
#' that this matrix should have the number of columns as the training
#' matrix, and that the columns must appear in the same order.
#' @param quantiles Vector of quantiles at which estimates are required.
#' @param quantiles Vector of quantiles at which estimates are required. If NULL, the quantiles
#' used to train the forest is used. Default is NULL.
#' @param num.threads Number of threads used in training. If set to NULL, the software
#' automatically selects an appropriate amount.
#' @param ... Additional arguments (currently ignored).
Expand Down Expand Up @@ -177,12 +178,16 @@ quantile_forest <- function(X, Y,
#' @export
predict.quantile_forest <- function(object,
newdata = NULL,
quantiles = c(0.1, 0.5, 0.9),
quantiles = NULL,
num.threads = NULL, ...) {
if (!is.numeric(quantiles) | length(quantiles) < 1) {
stop("Error: Must provide numeric quantiles")
} else if (min(quantiles) <= 0 | max(quantiles) >= 1) {
stop("Error: Quantiles must be in (0, 1)")
if (is.null(quantiles)) {
quantiles <- object[["quantiles.orig"]]
} else {
if (!is.numeric(quantiles) | length(quantiles) < 1) {
stop("Error: Must provide numeric quantiles")
} else if (min(quantiles) <= 0 | max(quantiles) >= 1) {
stop("Error: Quantiles must be in (0, 1)")
}
}

# If possible, use pre-computed predictions.
Expand Down