facebook / facebook/prophet

Components of Predict not adding up

Open
#2,512 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
20.4k
Forks
4.6k
Avg merge
19h 52m
Merged PRs (30d)
1

Description

Hello All,

Currently when I run multiplicative model with a regressor on my work data set, the sum of terms does not equal yhat. Here is reproducible example - the differences are small since the random numbers I am dealing with but as you can see they are not adding up. Any clue?

```
# Step 1: Setup and Installation
library(pacman)
p_load(prophet,dplyr)

# Data Preparation with Regressor
# Create a sequence of dates
ds <- seq(as.Date("2020-01-01"), as.Date("2022-01-01"), by="days")
# Create a dummy target variable
y <- rnorm(732, mean=20000, sd=5000)
# Create a dummy exogenous variable (e.g., marketing campaign: 1 for active days, 0 for others)
marketing_campaign <- rep(0, 732)
marketing_campaign[sample(1:732, 100)] <- 1 # Randomly activate the campaign on 100 days
df <- data.frame(ds, y, marketing_campaign)

# Initialize the Model with Multiplicative Seasonality
m <- prophet(seasonality.mode = "multiplicative")

# Add the Regressor to the Model
m <- add_regressor(m, 'marketing_campaign', mode = "multiplicative")

# Model Training
m <- fit.prophet(m, df)

# Forecasting with Regressor
future <- make_future_dataframe(m, periods = 365)
# Assume the marketing campaign is active on random 50 days in the future
future$marketing_campaign <- rep(0, nrow(future))
future$marketing_campaign[sample(1:nrow(future), 50)] <- 1

forecast <- predict(m, future)

forecast %>%
mutate(sum_of_terms = trend *
(1+ weekly) *
(1 + yearly) *
(1 + extra_regressors_multiplicative)) %>%
select( ds, yhat, sum_of_terms)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.