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

6 ビュー (過去 30 日間)
Darya
Darya 2015 年 11 月 16 日
回答済み: Aditya 2025 年 3 月 25 日
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.

回答 (1 件)

Aditya
Aditya 2025 年 3 月 25 日
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');

カテゴリ

Help Center および File ExchangeDimensionality Reduction and Feature Extraction についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by