Skip to content

Commit

Permalink
avoid using magic numbers in code
Browse files Browse the repository at this point in the history
Summary: introduce a global constant instead of a number in code.

Differential Revision: D67395481

fbshipit-source-id: 9c1de5d6a22eb9c5a6aad191b750217627657d6f
  • Loading branch information
islijepcevic authored and facebook-github-bot committed Dec 21, 2024
1 parent 35265cb commit 1aad463
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions kats/detectors/prophet_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
as a Detector Model.
"""

import json
import copy
import logging
import os
import sys
from contextlib import ExitStack
from enum import Enum
from typing import Any, Dict, List, Optional, Tuple, Union
from typing import Any, Dict, List, Optional, Union

import numpy as np
import pandas as pd
Expand All @@ -36,19 +38,17 @@
from scipy.stats import norm

P = ParameterSpecification("P")

PROPHET_TIME_COLUMN = "ds"
PROPHET_VALUE_COLUMN = "y"
PROPHET_YHAT_COLUMN = "yhat"
PROPHET_YHAT_LOWER_COLUMN = "yhat_lower"
PROPHET_YHAT_UPPER_COLUMN = "yhat_upper"
HOLIDAY_NAMES_COLUMN_NAME = "holiday"
HOLIDAY_DATES_COLUMN_NAME = "ds"
import copy
import os
import sys

NOT_SUPPRESS_PROPHET_FIT_LOGS_VAR_NAME = "NOT_SUPPRESS_PROPHET_FIT_LOGS"
# When less than 2 data points are left after outlier removal, Prophet will not
# be able to fit the model.
MIN_SAMPLES_REQUIRED_AFTER_OUTLIER_REMOVAL = 2


# this is a bug in prophet which was discussed in open source thread
Expand Down Expand Up @@ -479,10 +479,11 @@ def fit(
uncertainty_samples=self.outlier_removal_uncertainty_samples,
vectorize=self.vectorize,
)
if len(updated_data_df) < 2:
if len(updated_data_df) < MIN_SAMPLES_REQUIRED_AFTER_OUTLIER_REMOVAL:
logging.warning(
f"Outlier removal left {len(updated_data_df)} out of"
f" {len(data_df)} data points. Reverting to use all data."
f"Outlier removal left {len(updated_data_df)} which is"
f" less than {MIN_SAMPLES_REQUIRED_AFTER_OUTLIER_REMOVAL}. Reverting"
" to use all data."
)
else:
data_df = updated_data_df
Expand Down

0 comments on commit 1aad463

Please sign in to comment.