Clear Filters
Clear Filters

how to apply clustering time series data ?

67 views (last 30 days)
원석 서
원석 서 on 25 May 2022
Commented: Ram Krishnan on 26 Jan 2024
Hi, all
I am trying to do a clustering in time series data.
For example, I have eight days of data. How do I divide this variation into two clusters?
Clustering in Matlab's help is only about scatterplots.
Thanks in advanced.

Answers (1)

Paras Gupta
Paras Gupta on 16 Oct 2023
Hi 원석 서,
I understand that you want to perform clustering on time series data of eight days into two clusters. We can use Hierarchical clustering algorithm using Dynamic Time Warping (DTW) as the distance measure to achieve the same.
Since time-series data is high-dimensional and may have many outliers, the use of typical clustering algorithms like k-means is not the best approach. The key idea behind using DTW as the distance measure is that it can handle time series with different lengths and temporal distortions. DTW finds the optimal alignment between two time series by warping and stretching them to minimize the distance. This allows for more accurate comparisons and clustering of time series data.
You can refer the code below to perform DTW based clusteing on randomly generated time series data.
% Random time series data
numDays = 8; % Number of days
numTimePoints = 24; % Number of time points per day
data = zeros(numTimePoints, numDays);
for i = 1:numDays
% Generate random values for each time point
data(:, i) = rand(numTimePoints, 1);
end
% Calculate pairwise DTW distances
distances = pdist2(data', data', @(x,y) dtw(x', y'));
% Perform hierarchical clustering and cluster assignment
% The linkage method chosen is 'ward', which minimizes the variance when merging clusters
Z = linkage(distances, 'ward');
clusters = cluster(Z, 'MaxClust', 2);
% Display the clustering result for the 8 days
disp(clusters');
2 2 2 1 1 2 2 2
Please find below the documentations links for the functions used in the code above:
Hope this helps with your query.
  1 Comment
Ram Krishnan
Ram Krishnan on 26 Jan 2024
Paras,
This example was very helpful in writing code to determine clusters for blood pressure data for various subjects. Thank you!

Sign in to comment.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!