Skip to content

Commit

Permalink
fix prophet detector when irregular data
Browse files Browse the repository at this point in the history
Summary:
Fix the Prophet detector when data is irregular.
We resort to using all data if too much data is removed by outlier removal.

Reviewed By: yazovskymeta

Differential Revision: D67392638

fbshipit-source-id: b48abd49f07965df43020b2a8c235dea0d9eb266
  • Loading branch information
islijepcevic authored and facebook-github-bot committed Dec 18, 2024
1 parent 2691011 commit 16003d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion kats/detectors/prophet_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,12 +473,19 @@ def fit(
data_df = timeseries_to_prophet_df(total_data)

if self.remove_outliers:
data_df = self._remove_outliers(
updated_data_df = self._remove_outliers(
data_df,
self.outlier_threshold,
uncertainty_samples=self.outlier_removal_uncertainty_samples,
vectorize=self.vectorize,
)
if len(updated_data_df) < 2:
logging.warning(
f"Outlier removal left {len(updated_data_df)} out of"
f" {len(data_df)} data points. Reverting to use all data."
)
else:
data_df = updated_data_df
# seasonalities depends on current time series
self.seasonalities_to_fit = seasonalities_processing(
data_df[PROPHET_TIME_COLUMN], self.seasonalities
Expand Down
4 changes: 2 additions & 2 deletions kats/tests/detectors/test_prophet_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ def test_irregular_data_intervals(self, data_multiplier: float) -> None:
)

model = ProphetDetectorModel(remove_outliers=True)
with self.assertRaises(ValueError):
model.fit(irregular_ts)
model.fit(irregular_ts)
# No ValueError raised

def test_default_score_func(self) -> None:
"""Test that 'deviation_from_predicted_val' is used by default
Expand Down

0 comments on commit 16003d7

Please sign in to comment.