MATLAB Answers

How to performe k-medoids with pre-calculated distance matrix

15 views (last 30 days)
Konrad Warner
Konrad Warner on 1 Nov 2020
Answered: Aditya Patil on 20 Nov 2020
I want to performe k-mediods clustering with dtw distance on time series data and compare the cluster performance with the elbow-method.
The following script is doing fine:
klist = 2 : 20;
totSum = NaN;
for i = klist
[~,~,sumd] = kmedoids(X,i,'Distance',@dtw_dist);
totSum(i) = sum(sumd);
disp('done')
end
figure
plot(1:length(totSum),totSum) % plot of totals versus number (same as index)
except it takes a lot of time, because the distance matrix is large (23725x23725 double) and used 19 times .
So I pre-calculate the matrix ones (~12h):
dtwD = pdist(X,@(Xi,Xj) dtw_dist(Xi,Xj));
function d = dtw_dist(Xi, Xj, varargin)
[m,~] = size(Xj);
% preallocate
d = zeros(m,1);
for j=1:m
d(j) = dtw(Xi, Xj(j,:), varargin{:});
end
But is it usefull at all to speed up the clustering? Can I use the distance matrix with k-medoids? Maybe over linkage
clustTree = linkage(dtwD,'average');
that gives me a custertree? I couldnt figuere it out.

  0 Comments

Sign in to comment.

Answers (1)

Aditya Patil
Aditya Patil on 20 Nov 2020
Currently, it's not possible to pass distance matrix to kmedoids. I have brought this issue to the notice of concerned people.

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by