| ml_model | R Documentation |
Provides standardized estimation and prediction methods
infoOptional information/name of the model
formalsList with formal arguments of estimation and prediction functions
formulaFormula specifying response and design matrix
argsadditional arguments specified during initialization
fitActive binding returning estimated model object
new()Create a new prediction model object
ml_model$new( formula = NULL, estimate, predict = stats::predict, predict.args = NULL, info = NULL, specials, response.arg = "y", x.arg = "x", ... )
formulaformula specifying outcome and design matrix
estimatefunction for fitting the model (must be a function response, 'y', and design matrix, 'x'. Alternatively, a function with a single 'formula' argument)
predictprediction function (must be a function of model object, 'object', and new design matrix, 'newdata')
predict.argsoptional arguments to prediction function
infooptional description of the model
specialsoptional additional terms (weights, offset, id, subset, ...) passed to 'estimate'
response.argname of response argument
x.argname of design matrix argument
...optional arguments to fitting function
estimate()Estimation method
ml_model$estimate(data, ..., store = TRUE)
datadata.frame
...Additional arguments to estimation method
storeLogical determining if estimated model should be stored inside the class.
predict()Prediction method
ml_model$predict(newdata, ..., object = NULL)
newdatadata.frame
...Additional arguments to prediction method
objectOptional model fit object
update()Update formula
ml_model$update(formula, ...)
formulaformula or character which defines the new response
...Additional arguments to lower level functions
print()Print method
ml_model$print(...)
...Additional arguments to lower level functions
response()Extract response from data
ml_model$response(data, ...)
datadata.frame
...additional arguments to 'design'
design()Extract design matrix (features) from data
ml_model$design(data, ...)
datadata.frame
...additional arguments to 'design'
opt()Get options
ml_model$opt(arg, ...)
argname of option to get value of
...additional arguments to lower level functions
clone()The objects of this class are cloneable with this method.
ml_model$clone(deep = FALSE)
deepWhether to make a deep clone.
Klaus Kähler Holst
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))
# Reduce Ex. timing
a <- targeted::cv(models, data=iris)
cbind(coef(a), attr(args, "table"))
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.