how to apply clustering time series data ?

69 次查看(过去 30 天)
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.

回答(1 个)

Paras Gupta
Paras Gupta 2023-10-16
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 个评论
Ram Krishnan
Ram Krishnan 2024-1-26
Paras,
This example was very helpful in writing code to determine clusters for blood pressure data for various subjects. Thank you!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by