Learn R Programming

midr (version 0.5.0)

get.yhat: Wrapper Prediction Function

Description

get.yhat() works as a proxy prediction function for many classes of fitted models.

Usage

get.yhat(X.model, newdata, ...)

# S3 method for default get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for mid get.yhat(X.model, newdata, ...)

# S3 method for lm get.yhat(X.model, newdata, ...)

# S3 method for glm get.yhat(X.model, newdata, ...)

# S3 method for rpart get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for randomForest get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for ranger get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for svm get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for ksvm get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for AccurateGLM get.yhat(X.model, newdata, ...)

# S3 method for glmnet get.yhat(X.model, newdata, ...)

# S3 method for model_fit get.yhat(X.model, newdata, target = -1L, ...)

# S3 method for rpf get.yhat(X.model, newdata, target = -1L, ...)

Value

get.yhat() returns a numeric vector of model predictions for the newdata.

Arguments

X.model

a fitted model object.

newdata

a data.frame or matrix.

...

optional parameters that are passed to the prediction method for the model.

target

an integer or character vector specifying the target levels for the prediction, used for the models that returns a matrix or data.frame of class probabilities. Default is -1, representing the probability of not being the base level.

Details

get.yhat() is a wrapper prediction function for many classes of models. Although many predictive models have their own method of stats::predict(), the structure and the type of the output of these methods are not uniform. get.yhat() is designed to always return a simple numeric vector of model predictions. The design of get.yhat() is strongly influenced by DALEX::yhat().

Examples

Run this code
data(trees, package = "datasets")
model <- glm(Volume ~ ., trees, family = Gamma(log))
predict(model, trees[1:5, ], type = "response")
get.yhat(model, trees[1:5, ])

Run the code above in your browser using DataLab