最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

r - What is the difference between setting the engine parameter in linear_reg() implicitly vs. explicitly? - Stack Overflow

programmeradmin4浏览0评论

I am doing a course on linear regression with R using the tidymodels package and the sample code for specifying the linear regression model is:

linear_model_specification <- linear_reg() %>%
                                           set_engine(engine = "lm")

i.e. using the pipe operator and the set_engine() function. However, I do not understand the need to do this, as engine = "lm" is already the default argument in linear_reg. As far as I can see, the following code does the exact same thing without the need to use the pipe operator or set_engine():

linear_model_specification <- linear_reg()

Is there a programming reason to use set_engine() or was this done only for illustration purposes?

I am doing a course on linear regression with R using the tidymodels package and the sample code for specifying the linear regression model is:

linear_model_specification <- linear_reg() %>%
                                           set_engine(engine = "lm")

i.e. using the pipe operator and the set_engine() function. However, I do not understand the need to do this, as engine = "lm" is already the default argument in linear_reg. As far as I can see, the following code does the exact same thing without the need to use the pipe operator or set_engine():

linear_model_specification <- linear_reg()

Is there a programming reason to use set_engine() or was this done only for illustration purposes?

Share Improve this question asked Jan 20 at 18:40 phasedarrayphasedarray 497 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Either approach is fine.

If you want to set engine-specific parameters (or mark them for tuning), the more verbose set_engine("lm") would be required.

Bonus points: you can also set the mode in the first function (if the model can fit different modes). So you could do:

rand_forest("classification", "aorsf")

instead of

rand_forest() %>% 
  set_mode("classification") %>% 
  set_engine("aorsf")

if you have no additional arguments to specify.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论