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?
1 Answer
Reset to default 0Either 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.