Skip to content
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

Handle Non-Daily Time Resolutions in _time_resolution Calculation #1435

Open
paulogonc opened this issue Jan 25, 2025 · 2 comments
Open

Handle Non-Daily Time Resolutions in _time_resolution Calculation #1435

paulogonc opened this issue Jan 25, 2025 · 2 comments
Labels
MMM TVPs Related to time varying parameters

Comments

@paulogonc
Copy link

The current implementation of the _time_resolution calculation assumes that the data in self.X[self.date_column] is sampled at least in daily intervals. However, if the data is sampled at finer resolutions (e.g., seconds, minutes, or hours), the calculation self._time_resolution = (...).days results in a Zero.

if self.time_varying_intercept | self.time_varying_media:
            self._time_index = np.arange(0, X.shape[0])
            self._time_index_mid = X.shape[0] // 2
            self._time_resolution = (
                self.X[self.date_column].iloc[1] - self.X[self.date_column].iloc[0]
            ).days

When using time varaying intercept this will cause following error:

hsgp_kwargs.L = time_index_mid + DAYS_IN_YEAR / time_resolution
                                     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
ZeroDivisionError: float division by zero

Proposal to raise a ValueError after calculating self._time_resolution:

if self._time_resolution == 0:
      raise ValueError(
        "Time intervals in date_column are not in full days. Ensure that the dataset's timestamps are sampled at least in daily intervals."
    )

It took me a while to find out, that my timestamp data where sampled in the wrong resolution.

@wd60622
Copy link
Contributor

wd60622 commented Jan 25, 2025

What is the frequency of your data?

@paulogonc
Copy link
Author

My data is typically sampled at a frequency of 1 second, with a duration ranging from 1 to 5 hours. To use TVD with this data, I resample it to a daily frequency.

@wd60622 wd60622 added the TVPs Related to time varying parameters label Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MMM TVPs Related to time varying parameters
Projects
None yet
Development

No branches or pull requests

2 participants