base_estimator: Construct a Base Estimator

Description Usage Arguments Examples

View source: R/base_estimator.R

Description

This is a helper to bundle up the model fitting and prediction functions. All the models in this package expect fit and predict functions which take only data as arguments. x and y for fitting and only x for prediction.

Usage

1
base_estimator(fit_fn, predict_fn = stats::predict)

Arguments

fit_fn

a function taking only two parameters, the predictor variables x and a vector of outcomes y. When y is a factor, then fit_fn should fit a binary classification model. Otherwise, fit_fn should fit a regression model. This function should return an object which has an implementation of predict.

predict_fn

a function taking two parameters, the model object and the predictor variables newdata. The return value should be a numeric vector, the probability of the positive class in the case of a binary outcome, or the numeric response for a continuous outcome. stats::predict is used by default.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
  library(randomForest)

  rf_fit <- function(x, y) {
    randomForest(x, y, ntree = 200)
  }

  rf_predict <- function(m, newdata) {
    if (m$type == "classification") {
      return(stats::predict(m, newdata, type = "prob")[, 2])
    }

    stats::predict(m, newdata, type = "response")
  }

  rf <- base_estimator(rf_fit, rf_predict)

## End(Not run)

wlattner/hete documentation built on May 4, 2019, 12:57 a.m.