# Decision Tree for Time Series Anomaly Detection

I have learned recently to train decision trees in R with data. Now I have a problem in which the data is a time series and I would like to use the same approach to detect when the time series presents and anomalous pattern.

Is it possible to train decision trees with times series data? I see that the main problem in is the labelling for informing the algorithm when the time series is anomalous.

• First of all: Timeseries analysis (regression) is usually just "some" modelling algorithm applied to the lagged dataset, i.e. the input features are not 'weather', 'wind', etc (things that happen at the moment the prediction is made) but just the past value of the target variable before 1 timestep, the past value before 2 timesteps, and so on until some number k (it may be necessary to do some preprocessing in order to remove trends or so). In that sense you can use any regression algorithm (like a single decision tree) in order to predict the near future of the series. Aug 28, 2017 at 12:07
• You could then try to define 'anormal' as 'it deviates too much from the prediction'. However, there are many more algorithms out there in order to detect 'outliers'. For example: If you are not interested in "whether or not it behaves weird just now" but whether its fundamental properties change (in a certain way) then there is Bayesian Changepoint detection: hips.seas.harvard.edu/content/… Aug 28, 2017 at 12:09
• @FabianWerner, just to note, in time series models it is perfectly fine to have input features (usually lagged) such as "weather", "wind", etc. alongside the lagged values of the dependent variable, although some basic models (such as pure ARIMA or exponential smoothing) use only the lagged values of the dependent variable. Aug 28, 2017 at 12:53
• @RichardHardy: Yes, I was thinking about exactly that because this is usually one of the first models that one learns and is then surprised that one can also just apply 'any' model... in that sense ARIMA and TS analysis is nothing 'that special'... At least I was surprised when I realized that and I thougth that it might be a useful comment to add here :-) Aug 29, 2017 at 9:01
• @Ambesh: Yes, I was not sugesting the prediction in order for actually doing the prediction but in order to figure out exactly what you want: To find some deviance between the 'expected normal' behaviour [the prediction from the past] and the actual behaviour [the values you have observed] because according to what I understood you are looking for this criterion... How do you want to say what the 'normal' behaviour is otherwise? Aug 29, 2017 at 9:03