
Last chance! 50% off unlimited learning
Sale ends in
Create a model for use with the MachineShop package.
MLModel(
name = "MLModel",
label = name,
packages = character(),
response_types = character(),
predictor_encoding = c(NA, "model.matrix", "terms"),
params = list(),
grid = function(x, length, random, ...) NULL,
fit = function(formula, data, weights, ...) stop("no fit function"),
predict = function(object, newdata, times, ...) stop("no predict function"),
varimp = function(object, ...) NULL,
...
)
character name of the object to which the model is assigned.
optional character descriptor for the model.
character vector of packages required to use the model.
character vector of response variable types to which
the model can be fit. Supported types are "binary"
, =
"BinomialVariate"
, "DiscreteVariate"
, "factor"
,
"matrix"
, "NegBinomialVariate"
, "numeric"
,
"ordered"
, "PoissonVariate"
, and "Surv"
.
character string indicating whether the model is
fit with predictor variables encoded as a "model.matrix"
, a
data.frame containing the originally specified model "terms"
, or
unspecified (default).
list of user-specified model parameters to be passed to the
fit
function.
tuning grid function whose first agument x
is a
ModelFrame
of the model fit data and formula, followed by a
length
to use in generating sequences of parameter values, a number
of grid points to sample at random
, and an ellipsis (...
).
model fitting function whose arguments are a formula
, a
ModelFrame
named data
, case weights
, and an
ellipsis.
model prediction function whose arguments are the
object
returned by fit
, a ModelFrame
named
newdata
of predictor variables, optional vector of times
at
which to predict survival, and an ellipsis.
variable importance function whose arguments are the
object
returned by fit
, optional arguments passed from calls
to varimp
, and an ellipsis.
arguments passed from other methods.
MLModel
class object.
If supplied, the grid
function should return a list whose elements are
named after and contain values of parameters to include in a tuning grid to
be constructed automatically by the package.
Argument data
in the fit
function may be converted to a data
frame with the as.data.frame
function as needed. The function should
return the object resulting from the model fit.
Values returned by the predict
functions should be formatted according
to the response variable types below.
vector or column matrix of probabilities for the second level of binary factors or a matrix whose columns contain the probabilities for factors with more than two levels.
matrix of predicted responses.
vector or column matrix of predicted responses.
matrix whose columns contain survival probabilities at
times
if supplied or a vector of predicted survival means
otherwise.
The varimp
function should return a vector of importance values named
after the predictor variables or a matrix or data frame whose rows are named
after the predictors.
# NOT RUN {
## Logistic regression model
LogisticModel <- MLModel(
name = "LogisticModel",
response_types = "binary",
fit = function(formula, data, weights, ...) {
glm(formula, data = data, weights = weights, family = binomial, ...)
},
predict = function(object, newdata, ...) {
predict(object, newdata = newdata, type = "response")
},
varimp = function(object, ...) {
pchisq(coef(object)^2 / diag(vcov(object)), 1)
}
)
library(MASS)
res <- resample(type ~ ., data = Pima.tr, model = LogisticModel)
summary(res)
# }
Run the code above in your browser using DataLab