Closed midupree closed 4 years ago
The slides from class on Tuesday show you how to use the natural spline with step_ns
. The code you have there is doing penalized regression, this should just be regular linear model (using lm as the engine)
Hi @LucyMcGowan,
I also have a question on this exercise. I used the following code to create my recipe:
wage_recipe <- Wage %>%
recipe(wage ~ age, health_ins, jobclass, education, race) %>%
step_ns(age,deg_free = tune())
wage_recipe
Is this output giving me the degrees of freedom, such that I would say that we would use 1 degree of freedom for age (the predictor row)?
That is the correct recipe. Now you need to do cross validation & tune the model to get the degrees of freedom
@LucyMcGowan Okay so I was able to create a recipe and have the same question. For cross validation, would we use the coding from the cross-validation slides? I've attached. Would this give us the degrees of freedom once we incorporate the tune function?
Hi @LucyMcGowan I had exercise 3 working yesterday but today when I try to run it I'm getting this error and I'm not sure what it means, I didn't change any of the code from when it was running
@midupree no, for cross validation you can use similar code that you used in lab 4 (incorporating vfold_cv with tune_grid)
@michaeljurgens hmmm that is strange - can you try restarted your R session? (In the menu bar click Session > Restart R )
So I noticed that this may actually be the coding for question 4, but I am
I am also unsure if I have answered exercise 3 completely. In response to your last comment, are you just looking for the recipe in exercise 3, and then using tune to "decide how many degrees of freedom to use for the age variable" through cross validation and tuning the model all in exercise 4?
Wage
instead of wage_train
)penalty_spec
is. Exercise 2 asked you to specify linear_spec
that’s what you should use here grid
@LucyMcGowan I think I may have finally figured it out; Would we take the lowest rmse and then report the degrees of freedom listed there?
Yes exactly!
@LucyMcGowan Is there a difference between the rsq and rmse? Or do I just need to choose the model with the lowest value that is labeled rmse?
Yes, rsq
is R-squared, rmse
is the root mean squared error. You should use rmse
for this.
@LucyMcGowan I had a quick question on Number 3! I'm getting a little confused on the second part, which asks us to fit age using a natural spline. Use tune() to decide how many degrees of freedom to use for the age variable. I think I got the first part of creating a recipe, but I'm having trouble understanding how to use the natural spline. I've been searching through the slides with no avail. Is there any place I should look for reference to help me solve this problem? Here is what I have so far:
Thanks so much for all you do, Miriam