Skip to content

Instantly share code, notes, and snippets.

@MJacobs1985
Created February 21, 2022 13:56
Show Gist options
  • Select an option

  • Save MJacobs1985/61091921b996e261e30aeb000e4f58fa to your computer and use it in GitHub Desktop.

Select an option

Save MJacobs1985/61091921b996e261e30aeb000e4f58fa to your computer and use it in GitHub Desktop.
registerDoParallel(cores=8)
set.seed(123)
Eggs2<-day%>%
filter(location_identification==1)%>%
mutate(egg_count = zoo::na.aggregate(egg_count),
feed_provided = zoo::na.aggregate(feed_provided),
water_provided = zoo::na.aggregate(water_provided),
animals_actual = zoo::na.aggregate(animals_actual),
t_min_out = zoo::na.aggregate(t_min_out),
t_max_out = zoo::na.aggregate(t_min_out),
t_act_out = zoo::na.aggregate(t_min_out),
rh_act_in = zoo::na.spline(rh_act_in))%>%
dplyr::select(egg_count,
date_interval,
water_provided,
feed_provided,
animals_actual,
t_min_out,
t_max_out,
t_act_out,
rh_act_in)
myTimeControl <- trainControl(method = "timeslice",
initialWindow = 50,
horizon = 7,
fixedWindow = FALSE,
allowParallel = TRUE)
model_names <- c("glmnet", "lm",
"earth", "gam", "rpart",
"ctree", "gbm", "rf")
fits<-map(model_names,
~ train(
egg_count ~ . - 1,
data = Eggs2,
method = .x,
trControl = myTimeControl,
na.action=na.omit
))%>%
set_names(model_names)
resamps <- resamples(fits)
ss <- summary(resamps)
ss[[3]]$RMSE
trellis.par.set(caretTheme())
dotplot(resamps, metric = "RMSE")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment