- pdist2 - https://www.mathworks.com/help/stats/pdist2.html
- dtw - https://www.mathworks.com/help/signal/ref/dtw.html
- linkage - https://www.mathworks.com/help/stats/linkage.html
- cluster - https://www.mathworks.com/help/stats/cluster.html
how to apply clustering time series data ?
48 次查看(过去 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?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1010105/image.png)
Clustering in Matlab's help is only about scatterplots.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1010110/image.png)
Thanks in advanced.
0 个评论
回答(1 个)
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');
Please find below the documentations links for the functions used in the code above:
Hope this helps with your query.
1 个评论
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 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!