Can I use PCA and K-means to cluster movement trajectories?

5 visualizaciones (últimos 30 días)
Darya
Darya el 16 de Nov. de 2015
Respondida: Aditya el 25 de Mzo. de 2025
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.

Respuestas (1)

Aditya
Aditya el 25 de Mzo. de 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:
  1. Data Preparartion
  2. Apply PCA
  3. Apply K-means Clustering
  4. Analysis and Interpretation
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');

Categorías

Más información sobre Dimensionality Reduction and Feature Extraction 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