Skip to content

Commit

Permalink
Detectors module upgrades
Browse files Browse the repository at this point in the history
Summary: All pre-upgrade PSS2 changes for detectors and tests/detectors modules.

Reviewed By: islijepcevic

Differential Revision: D67505451

fbshipit-source-id: 0418fda3572843c5f6064524a6e8dbf75a748668
  • Loading branch information
proof-by-accident authored and facebook-github-bot committed Dec 20, 2024
1 parent 16003d7 commit 10dd208
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kats/detectors/cusum_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ def _reorganize_big_data(

multi_ts_val_df = pd.DataFrame(multi_ts_val).T

multi_ts_df = pd.concat([multi_ts_time_df, multi_ts_val_df], 1)
multi_ts_df = pd.concat([multi_ts_time_df, multi_ts_val_df], axis=1)
df_names = ["val_" + str(i) for i in range(multi_ts_val_df.shape[1])]
multi_ts_df.columns = ["time"] + df_names

Expand Down
4 changes: 3 additions & 1 deletion kats/detectors/multivariate_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def predict(
output_scores_df = self.model.anomaly_score_df

assert output_scores_df is not None
output_scores_df = output_scores_df[output_scores_df.index >= data.time.min()]
output_scores_df = output_scores_df[
output_scores_df.index.to_series().ge(data.time.min())
]

zeros = np.zeros(shape=(data.time.shape[0], output_scores_df.shape[1]))
padding = np.empty(
Expand Down
6 changes: 4 additions & 2 deletions kats/detectors/outlier.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __init__(

time_diff = data.time.sort_values().diff().dropna()
if len(time_diff.unique()) == 1: # check constant frequenccy
freq = time_diff.unique()[0].astype("int")
freq = time_diff.unique().astype("int")[0]
self.granularity_days: float = freq / (24 * 3600 * (10**9))
else:
raise RuntimeError(
Expand Down Expand Up @@ -342,7 +342,9 @@ def detector(self) -> pd.DataFrame:
anomaly_scores_t = pd.DataFrame(
anomaly_scores_t, index=[fcstTime], copy=False
)
anomaly_score_df = anomaly_score_df.append(anomaly_scores_t)
anomaly_score_df = pd.concat(
[anomaly_score_df, anomaly_scores_t], axis=0, ignore_index=False
)

self.anomaly_score_df = anomaly_score_df
return anomaly_score_df
Expand Down
4 changes: 3 additions & 1 deletion kats/detectors/seasonality.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ def get_fft_peaks(
pos_fft = fft.loc[fft["ampl"] > 0]
median = pos_fft["ampl"].median()
pos_fft_above_med = pos_fft[pos_fft["ampl"] > median]
mad = pos_fft_above_med["ampl"].mad()
mad = (
(pos_fft_above_med["ampl"] - pos_fft_above_med["ampl"].mean()).abs().mean()
)

threshold = median + mad * mad_threshold

Expand Down

0 comments on commit 10dd208

Please sign in to comment.