- Data Preparartion
- Apply PCA
- Apply K-means Clustering
- Analysis and Interpretation
Can I use PCA and K-means to cluster movement trajectories?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a series of trajectories (X,Y,Z) and would like to find out if different trajectories share some features. I was wondering if it makes sense to use PCA and then K-means to cluster trajectories? Thanks for suggestions.
0 commentaires
Réponses (1)
Aditya
le 25 Mar 2025
HI Darya,
Using PCA followed by K-means clustering is a reasonable and common approach to analyze and cluster trajectories based on shared features. Here's why this approach makes sense and how you can implement it:
Following is the code that you can try using:
% Assume trajectories is an N x (3*T) matrix where N is the number of trajectories
% and T is the number of time points (X, Y, Z concatenated)
% Standardize the data
trajectories_mean = mean(trajectories);
trajectories_std = std(trajectories);
trajectories_standardized = (trajectories - trajectories_mean) ./ trajectories_std;
% Apply PCA
[coeff, score, ~, ~, explained] = pca(trajectories_standardized);
% Choose the number of components (e.g., 95% variance explained)
cumulativeVariance = cumsum(explained);
numComponents = find(cumulativeVariance >= 95, 1);
reducedData = score(:, 1:numComponents);
% Apply K-means clustering
k = 3; % Example number of clusters
[idx, centroids] = kmeans(reducedData, k);
% Visualize the clusters (for example, using the first two components)
scatter(reducedData(:, 1), reducedData(:, 2), 10, idx, 'filled');
title('K-means Clustering of Trajectories');
xlabel('Principal Component 1');
ylabel('Principal Component 2');
0 commentaires
Voir également
Catégories
En savoir plus sur Dimensionality Reduction and Feature Extraction dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!