Help with understanding Tidymodel regression model example

Hi,

I am new to tidymodels and I am struggling to understand where some arguments in the tidymodel example comes from. I am using this example for reference: https://www.tidymodels.org/learn/models/parsnip-ranger-glmnet

I 'm able to follow the example right the way through but just at the end they plot the Sale_Price Vs. the predicted value from the test_result object for both the GLMNET and regularised regression model.

When I inspect the test_result variable I can see three columns, Sale_Price, random forest and glmnet yet the first line of the example uses gather with model and prediction and drops/de-selects Sale_Price:

# PLOT OF THE PERFORMANCE OF THE REGULARISED GLMNET Vs. THE RANDOM FOREST MODEL 
test_results %>% 
  gather(model, prediction, -Sale_Price) %>% 
  ggplot(aes(x = prediction, y = Sale_Price)) + 
  geom_abline(col = "green", lty = 2) + 
  geom_point(alpha = .4) + 
  facet_wrap(~model) + 
  coord_fixed()

My question here is, what is the purpose of gather and where are model and prediction coming from as they're not in my test_results object?

Thank you.

gather() is reshaping your test_results data frame into a long format and those variables are created in consequence as key and value variables. See the documentation for the function:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.