how to apply clustering time series data ?

68 ビュー (過去 30 日間)
원석 서
원석 서 2022 年 5 月 25 日
コメント済み: Ram Krishnan 2024 年 1 月 26 日
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 Center および File ExchangeStatistics 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