sta-363-s20 / community

Discussion, Q&A, everything you want to say, formatted nicely
1 stars 0 forks source link

Ex 4 on Lab 5 #65

Closed erincperry closed 4 years ago

erincperry commented 4 years ago

@LucyMcGowan I am unable to get my code for the exercise 4 to run This is what I have so far:

set.seed(7)
Wage_cv <- vfold_cv(Wage, v = 10)
results <- fit_resamples(linear_spec,
              preprocessor = wage_rec,
              resamples = Wage_cv)
grid <- expand_grid(deg_free = seq(1,10, by = 1)) 
tuning <- tune_grid(linear_spec,
                   wage_rec,
                    grid = grid,
                   resamples = Wage_cv)

tuning %>%
 collect_metrics() %>%
  filter(.metric == "deg_free") %>%
  arrange(mean())

The error says x Fold01: recipe: Error in df - 1L: non-numeric argument to ... x Fold02: recipe: Error in df - 1L: non-numeric argument to ... x Fold03: recipe: Error in df - 1L: non-numeric argument to ...

Do you have any advice / suggestions on how to fix this?

LucyMcGowan commented 4 years ago

Can you send your recipe code?

erincperry commented 4 years ago

wage_rec <- recipe(wage ~ age, health_ins, jobclass, education, race, data = Wage) %>% step_ns(age, deg_free = tune()) wage_rec

LucyMcGowan commented 4 years ago

Looks like a type (, should be +)

wage_rec <- recipe(wage ~ age + health_ins + jobclass + education +race, data = Wage) %>%
step_ns(age, deg_free = tune())
wage_rec
erincperry commented 4 years ago

Thank you! I changed to the plus signs, but I am still getting the same error when I run the last code. Is there anything else I should try?

LucyMcGowan commented 4 years ago

Ahh I see it 👀 the problem is actually here:

tuning %>%
 collect_metrics() %>%
  filter(.metric == "deg_free") %>%
  arrange(mean())

the filter line is filtering the .metric column. This column has two potential values rmse or rsq, you want to use rmse so that is what you should filter based on (not "deg_free")

erincperry commented 4 years ago

oh okay perfect! I will try that. Thank you!

nuripark10 commented 4 years ago

Hi Dr. McGowan, I have got my degrees of freedom as well as rmse, but do we need to do the "final_spec" just like we did in lab 4?

LucyMcGowan commented 4 years ago

Nope, you can skip that step!

peytontarry commented 4 years ago

@LucyMcGowan I'm also having trouble getting my code to run for this exercise. My code looks a little different from Erin's, but I think the error message that I'm receiving is similar. Do you have any pointers on how to fix mine? Do I need to create an object "grid" and add in a fit_resamples line like above?

Screen Shot 2020-03-25 at 10 24 10 AM
peytontarry commented 4 years ago

@LucyMcGowan In case it's helpful, this is my recipe code!

Screen Shot 2020-03-25 at 10 28 54 AM
LucyMcGowan commented 4 years ago

There’s a small typo (step_ns() should be for age not wage)

peytontarry commented 4 years ago

@LucyMcGowan Thank you so much!