Augment data with predictions
augment()
will add column(s) for predictions to the given data.
## S3 method for class 'model_fit' augment(x, new_data, ...)
For regression models, a .pred
column is added. If x
was created using
fit()
and new_data
contains the outcome column, a .resid
column is
also added.
For classification models, the results include a column called .pred_class
as well as class probability columns named .pred_{level}
.
car_trn <- mtcars[11:32,] car_tst <- mtcars[ 1:10,] reg_form <- linear_reg() %>% set_engine("lm") %>% fit(mpg ~ ., data = car_trn) reg_xy <- linear_reg() %>% set_engine("lm") %>% fit_xy(car_trn[, -1], car_trn$mpg) augment(reg_form, car_tst) augment(reg_form, car_tst[, -1]) augment(reg_xy, car_tst) augment(reg_xy, car_tst[, -1]) # ------------------------------------------------------------------------------ data(two_class_dat, package = "modeldata") cls_trn <- two_class_dat[-(1:10), ] cls_tst <- two_class_dat[ 1:10 , ] cls_form <- logistic_reg() %>% set_engine("glm") %>% fit(Class ~ ., data = cls_trn) cls_xy <- logistic_reg() %>% set_engine("glm") %>% fit_xy(cls_trn[, -3], cls_trn$Class) augment(cls_form, cls_tst) augment(cls_form, cls_tst[, -3]) augment(cls_xy, cls_tst) augment(cls_xy, cls_tst[, -3])
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.