case_weights | R Documentation |
Extract the case weights from an object.
case_weights(object, newdata = NULL)
object |
model fit result, |
newdata |
dataset from which to extract the weights if given; otherwise,
|
## Training and test sets
inds <- sample(nrow(ICHomes), nrow(ICHomes) * 2 / 3)
trainset <- ICHomes[inds, ]
testset <- ICHomes[-inds, ]
## ModelFrame case weights
trainmf <- ModelFrame(sale_amount ~ . - built, data = trainset, weights = built)
testmf <- ModelFrame(formula(trainmf), data = testset, weights = built)
mf_fit <- fit(trainmf, model = GLMModel)
rmse(response(mf_fit, testmf), predict(mf_fit, testmf),
case_weights(mf_fit, testmf))
## Recipe case weights
library(recipes)
rec <- recipe(sale_amount ~ ., data = trainset) %>%
role_case(weight = built, replace = TRUE)
rec_fit <- fit(rec, model = GLMModel)
rmse(response(rec_fit, testset), predict(rec_fit, testset),
case_weights(rec_fit, testset))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.