r descr_models("linear_reg", "quantreg")
This model has the same structure as the model fit by lm()
, but instead of optimizing the sum of squared errors, it optimizes "quantile loss" in order to produce better estimates of the predictive distribution.
This engine has no tuning parameters.
This model only works with the "quantile regression"
model and requires users to specify which areas of the distribution to predict via the quantile_levels
argument. For example:
linear_reg() %>% set_engine("quantreg") %>% set_mode("quantile regression", quantile_levels = (1:3) / 4) %>% translate()
When multiple quantile levels are predicted, there are multiple predicted values for each row of new data. The predict()
method for this mode produces a column named .pred_quantile
that has a special class of "quantile_pred"
, and it contains the predictions for each row.
For example:
library(modeldata) rlang::check_installed("quantreg") n <- nrow(Chicago) Chicago <- Chicago %>% select(ridership, Clark_Lake) Chicago_train <- Chicago[1:(n - 7), ] Chicago_test <- Chicago[(n - 6):n, ] qr_fit <- linear_reg() %>% set_engine("quantreg") %>% set_mode("quantile regression", quantile_levels = (1:3) / 4) %>% fit(ridership ~ Clark_Lake, data = Chicago_train) qr_fit qr_pred <- predict(qr_fit, Chicago_test) qr_pred
We can unnest these values and/or convert them to a rectangular format:
as_tibble(qr_pred$.pred_quantile) as.matrix(qr_pred$.pred_quantile)
The "Fitting and Predicting with parsnip" article contains examples for linear_reg()
with the "quantreg"
engine.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.