Time Series Clustering: Techniques and Applications

Last Updated : 30 Sep, 2025

Time series clustering is an unsupervised learning technique that groups data sequences collected over time based on their similarities. Unlike traditional clustering, it accounts for temporal dependencies, shifts in trend and variable sequence lengths. The objective is to identify hidden structures and patterns in temporal data for effective analysis and decision-making.

Similarity Measures

  • Euclidean Distance: Straight-line distance, simple but sensitive to time shifts.
  • Dynamic Time Warping (DTW): Aligns sequences by stretching/compressing time and its robust to shifts.
  • Correlation-Based Measures: Compare shapes rather than exact values.

Time Series Clustering Techniques

1. Shape-Based Clustering

Shape-based clustering directly compares the overall shape of time series to group similar patterns. Instead of focusing on raw values, it looks at structural similarity.

  • Often uses autocorrelation, cepstral coefficients or distance measures like DTW.
  • Suitable when pattern alignment and similarity of curves is more important than exact magnitude.
  • Works with k-means, hierarchical clustering or DTW-based methods.
Python
import numpy as np
from tslearn.preprocessing import TimeSeriesScalerMeanVariance
from tslearn.clustering import TimeSeriesKMeans
from tslearn.utils import to_time_series_dataset

np.random.seed(0)
time = np.linspace(0, 10, 50)
series = [np.sin(time + shift) for shift in np.linspace(0, 3, 10)]
dataset = to_time_series_dataset(series)

scaler = TimeSeriesScalerMeanVariance()
dataset_scaled = scaler.fit_transform(dataset)

model = TimeSeriesKMeans(n_clusters=3, metric="dtw", random_state=0)
labels = model.fit_predict(dataset_scaled)

print("Cluster Labels (Shape-Based):", labels)

Output:

Cluster Labels (Shape-Based): [2 2 2 0 0 0 0 0 1 1]

2. Feature-Based Clustering

Feature-based clustering transforms time series into a set of statistical or frequency-domain features, then applies standard clustering algorithms.

  • Features include mean, variance, autocorrelation, seasonality, Fourier coefficients or wavelets.
  • Converts time series into a fixed-length feature vector.
  • Allows the use of traditional clustering methods like k-means, GMM and hierarchical clustering.
Python
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
from scipy.fftpack import fft
np.random.seed(0)
time = np.linspace(0, 10, 100)
series = [np.sin(time + phase) + np.random.normal(0, 0.1, 100)
          for phase in [0, 1, 2, 3]]
data = np.array(series)

features = []
for s in data:
    mean = np.mean(s)
    std = np.std(s)
    freq = np.abs(fft(s)[:5])
    features.append([mean, std] + list(freq))

features = np.array(features)

scaler = StandardScaler()
features_scaled = scaler.fit_transform(features)

kmeans = KMeans(n_clusters=2, random_state=0)
labels = kmeans.fit_predict(features_scaled)

print("Cluster Labels (Feature-Based):", labels)

Output:

Cluster Labels (Feature-Based): [0 1 0 0]

3. Model-Based Clustering

Model-based clustering assumes each series is generated from a probabilistic model like Gaussian distributions or Hidden Markov Models.

  • Clusters are represented as mixtures of probability distributions.
  • Commonly uses Gaussian Mixture Models (GMMs).
  • Best when data can be explained by statistical distributions rather than raw shapes.
Python
import numpy as np
from sklearn.mixture import GaussianMixture
from sklearn.preprocessing import StandardScaler

np.random.seed(0)
series1 = np.random.normal(0, 1, 50)
series2 = np.random.normal(5, 1, 50)
series3 = np.random.normal(-3, 1, 50)
data = np.vstack([series1, series2, series3])

features = np.array([[np.mean(s), np.std(s)] for s in data.reshape(3, -1)])

scaler = StandardScaler()
features_scaled = scaler.fit_transform(features)

gmm = GaussianMixture(n_components=3, random_state=0)
labels = gmm.fit_predict(features_scaled)

print("Cluster Labels (Model-Based):", labels)

Output:

Cluster Labels (Model-Based): [2 0 1]

Applications

  • Finance: Identifying similar stock price patterns, clustering financial instruments and detecting anomalies in trading activities.
  • Healthcare: Grouping patients with similar vital sign trends or disease progression for better monitoring and personalized treatment.
  • Energy Sector: Clustering electricity consumption patterns to optimize load balancing, pricing strategies and demand forecasting.
  • Climate & Weather Analysis: Grouping temperature, rainfall or wind speed time series to study climate zones and forecast environmental changes.
  • Industrial IoT & Predictive Maintenance: Analyzing sensor signals from machines to detect early failure signs and schedule maintenance.
  • Retail & E-commerce: Segmenting customers based on purchasing behavior over time to improve targeted marketing and recommendations.
Comment