# Using STL(Seasonal-Trend decomposition using LOESS) for Anomaly detection

I am using STL to decompose my time series data in Season, trend and residual and then by applying this(see below) on residual. I am detecting the anomaly


resid_mu = resid.mean()
resid_dev = resid.std()

//anything outside lower and upper limit is anamoly
lower = resid_mu - 3*resid_dev
upper = resid_mu + 3*resid_dev



If I do this on 1 year of data it is giving a good result but now if I get new data say for 1 new day how can I use older decomposition data so that I have to process for 1 day only and not for 1 year+1 day.

• What is the minimum amount of data to detect seasonality? Is one day enough? Jun 28, 2021 at 10:05
• What is the minimum amount of data to detect seasonality? 1 week Is one day enough? I am getting incremental data daily. Jun 29, 2021 at 10:54
• In order to make a prediction on the next day (or the next several days), your model should consider several previous days, months or even years, depending on seasonality period. You cannot make a prediction based on a single value, you need to be based on enough values (maybe values on a year for instance) to detect the seasonal behaviours. Jun 29, 2021 at 11:36