kmean with dtw distance

16 vues (au cours des 30 derniers jours)
Vincent Derozier
Vincent Derozier le 7 Sep 2020
Hi, I want to use kmedoid() clustering (or kmeans no matter) with dtw() distance, but when i tried predefined funtions kmedoid() , dtw() and pdist() an error occur, I think it's caused by the format of the output of pdist is incompatible with the parameter distance of kmeans!!
Thanks for help me to corrert my code (below)?
function d = dtwdist(Xi, Xj)
[m,n] = size(Xj);
d = zeros(m,1);
for j=1:m
d(j) = dtw(Xi, Xj(j,:));
end
end
[...]
[IDX,C,sumd,D] = kmedoids(data,nbClust,'distance',pdist(data,@(Xi,Xj) dtwdist(Xi,Xj)));

Réponses (1)

Anmol Dhiman
Anmol Dhiman le 16 Sep 2020
Hi Vincent,
In my understanding you want to use your custom distance function (dtwdist) with kmediod(). For this you don't need to use pdist function when calling kmedoid, You can simply pass the function handle of your custom function (dtwdist) and get your output.
The Name-Value pair 'Distance' only expect string or function handle. If using pdist, it gives an array as output which is invalid input for "Distance" name value pair. You can refer to following piece of code for refernce.
[IDX,C,sumd,D] = kmedoids(X,2,'Distance',@dtwdist);
Regards,
Anmol Dhiman

Catégories

En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by