I'm trying to plot the train set and the prediction in the same graph using autoplot but, instead of the value in the original scale, the output include the value in the transformed scale. My train set has both the value in original scale and the value scaled. Is there a way to do this?
This is my code:
#train the model
fit_prophet<-train%>%model(prophet(OrdAdj))
#forecast
fc_prophet <- fit_prophet %>%
forecast(h = "1 month")
#convert back in the original scale
fc_prophet$QtyEur <- InvBoxCox(fc_prophet$.mean, lambda)
class(fc_prophet$QtyEur)
fc_prophet%>%autoplot(train)
New code implemented after the suggestion:
fit_prophet<-train%>%model(prophet(box_cox(QtyEur, lambda=lambda)))
#forecast
fc_prophet <- fit_prophet %>%
forecast(h = "1 month")
fc_prophet%>%
autoplot(train%>%filter(Date>="2023-01-01"))+
geom_line(data=test,mapping=aes(y=QtyEur, x=Date), col="red")+
labs(title="Train + Test vs Prediction")
You appear to be confusing the way the forecast package works and the way the fable package works. With the fable package, you can include the transformation in the modelling step like this:
Then the forecasts will be automatically back transformed to be on the correct scale.