Provides standardized estimation and prediction methods
info
Optional information/name of the model
formals
List with formal arguments of estimation and prediction functions
formula
Formula specifying response and design matrix
args
additional arguments specified during initialization
fit
Active binding returning estimated model object
new()
Create a new prediction model object
formula
formula specifying outcome and design matrix
estimate
function for fitting the model (must be a function response, 'y', and design matrix, 'x'. Alternatively, a function with a single 'formula' argument)
predict
prediction function (must be a function of model object, 'object', and new design matrix, 'newdata')
predict.args
optional arguments to prediction function
info
optional description of the model
specials
optional additional terms (weights, offset, id, subset, ...) passed to 'estimate'
response.arg
name of response argument
x.arg
name of design matrix argument
...
optional arguments to fitting function
estimate()
Estimation method
predict()
Prediction method
update()
Update formula
print()
Print method
design()
Extract design matrix (features) from data
data(iris)
rf <- function(formula, ...)
ml_model$new(formula, info="grf::probability_forest",
estimate=function(x,y, ...) grf::probability_forest(X=x, Y=y, ...),
predict=function(object, newdata)
predict(object, newdata)$predictions, ...)
args <- expand.list(num.trees=c(100,200), mtry=1:3,
formula=c(Species ~ ., Species ~ Sepal.Length + Sepal.Width))
models <- lapply(args, function(par) do.call(rf, par))
x <- models[[1]]$clone()
x$estimate(iris)
predict(x, newdata=head(iris))
#> setosa versicolor virginica
#> [1,] 0.9869394 0.007651515 0.005409091
#> [2,] 0.9643561 0.033068182 0.002575758
#> [3,] 0.9870833 0.011250000 0.001666667
#> [4,] 0.9804167 0.017916667 0.001666667
#> [5,] 0.9927727 0.001818182 0.005409091
#> [6,] 0.9184302 0.059244006 0.022325758
# Reduce Ex. timing
a <- targeted::cv(models, data=iris)
cbind(coef(a), attr(args, "table"))
#> brier -logscore num.trees mtry
#> model1 0.09876431 0.2162048 100 1
#> model2 0.09676479 0.2133566 200 1
#> model3 0.08640535 0.1858628 100 2
#> model4 0.08757708 0.1854903 200 2
#> model5 0.08523466 0.1714144 100 3
#> model6 0.08144620 0.1673086 200 3
#> model7 0.33669049 0.5520703 100 1
#> model8 0.34025907 0.5600141 200 1
#> model9 0.33974766 0.5507261 100 2
#> model10 0.33571456 0.5493773 200 2
#> model11 0.33823288 0.5501077 100 3
#> model12 0.33389234 0.5471020 200 3
#> formula
#> model1 Species ~ .
#> model2 Species ~ .
#> model3 Species ~ .
#> model4 Species ~ .
#> model5 Species ~ .
#> model6 Species ~ .
#> model7 Species ~ Sepal.Length + Sepal.Width
#> model8 Species ~ Sepal.Length + Sepal.Width
#> model9 Species ~ Sepal.Length + Sepal.Width
#> model10 Species ~ Sepal.Length + Sepal.Width
#> model11 Species ~ Sepal.Length + Sepal.Width
#> model12 Species ~ Sepal.Length + Sepal.Width
ff <- ml_model$new(estimate=function(y,x) lm.fit(x=x, y=y),
predict=function(object, newdata) newdata%*%object$coefficients)
## tmp <- ff$estimate(y, x=x)
## ff$predict(x)