-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
recursive() error - glmnet #76
Comments
Hi @mdancho84 , I can't reproduce the error just with the version before yesterday's patch because of the XGboost issue #75 . But when I upgrade just to the latest version, it does produce the error you mention, so it must be something we modified to fix that problem. In principle it should be in modeltime_forecast() function. I have not been able to check it, but my intuition tells me that the problem is here:
Once updated:
Regards, |
That's interesting. I'll have to go through the code I added. It's very odd since I'm only adding an ID when it's necessary. I did remove some columns to make them consistent with .first_slice and .nth_slice. Not sure if that was the error. Will need to do a thorough review. Should be able to tackle later this week. |
Ok, I'm getting somewhere. Here's what We can see it's getting invoked in the traceback. Which means it never hits our |
A working example. library(modeltime)
library(tidymodels)
library(tidyverse)
library(lubridate)
library(timetk)
FORECAST_HORIZON <- 24
m4_extended <- m4_monthly %>%
group_by(id) %>%
future_frame(
.length_out = FORECAST_HORIZON,
.bind_data = TRUE
) %>%
ungroup()
#> .date_var is missing. Using: date
lag_roll_transformer_grouped <- function(data){
data %>%
group_by(id) %>%
tk_augment_lags(value, .lags = 1:24) %>%
tk_augment_slidify(
.value = contains("lag1"),
.f = ~mean(.x, na.rm = T),
.period = c(12, 24, 36),
.partial = TRUE
) %>%
select(-value_lag1) %>%
ungroup()
}
m4_lags <- m4_extended %>%
lag_roll_transformer_grouped()
train_data <- m4_lags %>%
drop_na()
future_data <- m4_lags %>%
filter(is.na(value))
splits <- train_data %>%
time_series_split(date, assess = FORECAST_HORIZON, cumulative = TRUE)
recipe_spec <- recipe(value ~ ., data = training(splits)) %>%
step_timeseries_signature(date) %>%
step_rm(matches("(.xts$)|(.iso$)|(hour)|(minute)|(second)|(am.pm)")) %>%
step_rm(date) %>%
step_zv(all_predictors()) %>%
step_normalize(date_index.num, date_year) %>%
step_dummy(all_nominal(), one_hot = TRUE)
model_fit_lm_recursive <- workflow() %>%
add_model(linear_reg() %>% set_engine("lm")) %>%
add_recipe(recipe_spec) %>%
fit(training(splits)) %>%
recursive(
id = "id",
transform = lag_roll_transformer_grouped,
train_tail = panel_tail(training(splits), id, FORECAST_HORIZON)
)
model_fit_glmet_recursive <- workflow() %>%
add_model(linear_reg(penalty = 100, mixture = 0.5) %>% set_engine("glmnet")) %>%
add_recipe(recipe_spec) %>%
fit(training(splits)) %>%
recursive(
id = "id",
transform = lag_roll_transformer_grouped,
train_tail = panel_tail(training(splits), id, FORECAST_HORIZON)
)
calibration_tbl <- modeltime_table(
model_fit_lm_recursive,
model_fit_glmet_recursive
) %>%
modeltime_calibrate(testing(splits))
calibration_tbl %>% modeltime_accuracy()
#> # A tibble: 2 x 9
#> .model_id .model_desc .type mae mape mase smape rmse rsq
#> <int> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 LM Test 1100. 30.5 0.158 29.8 1622. 0.855
#> 2 2 GLMNET Test 964. 26.6 0.139 25.2 1372. 0.899
forecast_tbl <- modeltime_table(
model_fit_lm_recursive,
model_fit_glmet_recursive
) %>%
modeltime_forecast(
new_data = testing(splits),
actual_data = bind_rows(training(splits), testing(splits)),
keep_data = TRUE
) %>%
group_by(id)
forecast_tbl %>%
plot_modeltime_forecast(
.facet_ncol = 2,
.interactive = F
)
Created on 2021-03-25 by the reprex package (v1.0.0) |
This issue happens with
glmnet
models only.Reproducible Example
The text was updated successfully, but these errors were encountered: