How can I use time series model for early warning or anomaly detection that may happen in future?

36 views Asked by At

I have monthly data and converted my y to log(y) with some extra regressors to use prophet model. I have 60 data points from 201601 till 202008.

Here is my mode:

holidays = pd.DataFrame({
        "holiday":"New_Year",
        "ds": pd.to_datetime(["2015-11-30","2016-11-30","2017-11-30","2018-11-30","2019-11-30","2020-11-30"]),
        "lower_window":-15,
        "upper_window":90
    })
m = Prophet(interval_width=0.95,holidays=holidays)

for c in cols:
        m.add_regressor(c)

m.fit(data)
train_forecast = m.predict(data)

I train and test on same data as I have just 60 points.

Now coming to important question, I want to flag off any outlier/anaomaly as an early waring in future months ( 6 months of forecast let's say) from 202009 to 202012

Current Approach: I take mean and standard deviation of yhat and then draw 1std, 2std and 3std lines on those 60 data points. And whatever falls beyond 3std, I flag it as early warning. Is this the right way?

Question 1: Since I have taken interval_width=0.95, so will my prediction for future data always fall inside 3 std.deviation of predicted values? In that case I will never get anomaly.

I also seen this approach in many blogs:

y_original > forecasted['yhat_upper'] = 1
y_original< forecasted['yhat_lower']= -1

But for unseen data ( 6 month's future) I will not be having y_original right?? So, the method will not work for forecasted values.

Question2: how can I use existing Prophet model to flag anomaly for future forecasted values?

0

There are 0 answers