how to apply clustering time series data ?

68 visualizaciones (últimos 30 días)
원석 서
원석 서 el 25 de Mayo de 2022
Comentada: Ram Krishnan el 26 de En. de 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.

Respuestas (1)

Paras Gupta
Paras Gupta el 16 de Oct. de 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 comentario
Ram Krishnan
Ram Krishnan el 26 de En. de 2024
Paras,
This example was very helpful in writing code to determine clusters for blood pressure data for various subjects. Thank you!

Iniciar sesión para comentar.

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by