Description Usage Arguments Examples
View source: R/base_estimator.R
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.
1 | base_estimator(fit_fn, predict_fn = stats::predict)
|
fit_fn |
a function taking only two parameters, the predictor variables
|
predict_fn |
a function taking two parameters, the model |
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.