You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to tune a Prophet model and wanted then to check the model. I am just at the beginning of learning how to use modeltime, so I wanted to check the model using prophet. Herewith the code that I have written:
library(tidyverse)
library(tidymodels)
library(modeltime)
library(timetk)
# Define the Prophet model specification
prophet_spec <-
prophet_reg() |>
set_args(
seasonality_yearly = TRUE,
seasonality_weekly = TRUE,
seasonality_daily = FALSE,
prior_scale_changepoints = tune(),
prior_scale_seasonality = tune(),
prior_scale_holidays = tune()
) |>
set_engine("prophet")
# Define the grid of tuning parameters
tune_grid <-
grid_latin_hypercube(
prior_scale_changepoints(),
prior_scale_seasonality(),
prior_scale_holidays(),
size = 10 # Number of combinations to try
)
splits <- initial_time_split(m750)
train <- training(splits)
test <- testing(splits)
# Define the rolling origin cross-validation
folds <-
rolling_origin(
train,
initial = 100,
assess = 10,
skip = 15
)
# Set up the workflow
workflow <-
recipe(value ~ date, data = train) |>
workflow(prophet_spec)
# Performing tuning
tune_results <-
tune_grid(
workflow,
resamples = folds,
grid = tune_grid
)
# Evaluate and select the best model
best_model <- select_best(tune_results, metric = "rmse")
# Finalize the model with the best hyperparameters
final_model <- finalize_workflow(workflow, best_model)
# Fit the finalized workflow on the full dataset
final_fit <- final_model |>
fit(data = train)
# Extract the fitted Prophet model
fitted_prophet <- extract_fit_engine(final_fit)
# Create future dataframe
future <- make_future_dataframe(fitted_prophet, periods = 15)
# Make forecasts
forecast <- predict(fitted_prophet, future)
However, when I try to extract the fit from the workflow, using extract_fit_engine() and I use it to create the future with make_future_dataframe(), I get the following error:
> future <- make_future_dataframe(fitted_prophet, periods = 15)
Error in make_future_dataframe(fitted_prophet, periods = 15) :
Model must be fit before this can be used.
As far as I have understood the problem, it seems that extract_fit_engine() doesn't extract the fit in the correct format as it should. Is there any chance that this can be fixed?
Thank you and thank you for any help you can give me.
Andrea
The text was updated successfully, but these errors were encountered:
Hi there!
I was trying to tune a Prophet model and wanted then to check the model. I am just at the beginning of learning how to use modeltime, so I wanted to check the model using prophet. Herewith the code that I have written:
However, when I try to extract the fit from the workflow, using
extract_fit_engine()
and I use it to create thefuture
withmake_future_dataframe()
, I get the following error:As far as I have understood the problem, it seems that
extract_fit_engine()
doesn't extract the fit in the correct format as it should. Is there any chance that this can be fixed?Thank you and thank you for any help you can give me.
Andrea
The text was updated successfully, but these errors were encountered: