# Stationary time series for clustering algorithms

I have a set of time series data that I would like to feed into a clustering algorithm (like k-means, using dynamic time warping as the distance function). After standardizing the data with mean 0 and variance 1, the k-means classifier generated a batch of centroids that seemed to fit the data pretty well.

The only question I have is whether the data should be stationary. Models such as ARIMA require for the data to be stationary due to the nature of it. However, the data I want to cluster is mortgage rates as a function of time, which could be subject to seasonal trends, which could be useful when clustering other future time series data.

The question is: do clustering algorithms for time series data generally require for the data to be stationary?

• What do you mean by standardized - taking out seasonality or scaling all variables to a common range (like from 0 to 1)? – El Burro Jun 19 '19 at 8:43
• @ElBurro oh I'm so sorry, for some reason I used standardization and stationary interchangeably. When I mean that I standardized my data, I mean that I just standardized by making each time series have an overall mean of 0 and a variance of 1. This, however, does not mean that each time series is stationary. Actually, I checked and none of my data, before and after being standardized, are stationary. So my question is whether clustering algorithms for time series, like k-means for instance, require for the data to be stationary. After thinking about it I don't believe it's the case... – Cristian Vives Jun 19 '19 at 18:55
• The reason being that if I'm trying to cluster similar time series, then seasonality can be an important feature to distinguish different time series. I'm not trying to do forecasting, which in that case I know it's necessary for a time series to be stationary. – Cristian Vives Jun 19 '19 at 18:58
• Ok but all dimensions have the same dimensions- which is good as most clustering is essentially n-dimensional distance calculations – El Burro Jun 20 '19 at 16:23
• is your input for the clustering an entire time series or one datapoint (in multiple dimensions)? – El Burro Jun 20 '19 at 16:25

• Sure! Given that the data is represented as an array, where each entry in the array is a time series, I first standardize the array with the following code: [scipy.stats.mstats.zscore(arr,axis=0) for arr in array] After applying zscore standardization, I use the tslearn python module to cluster my data. I use the kmeans for time series clustering algorithm, as seen here: [tslearn.readthedocs.io/en/latest/gen_modules/clustering/… As you can see, there is an option to use DTW as your metric. – Cristian Vives Jun 24 '19 at 17:32