# kmean with dtw distance

12 Ansichten (letzte 30 Tage)
Vincent Derozier am 7 Sep. 2020
Beantwortet: Anmol Dhiman am 16 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)));
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Antworten (1)

Anmol Dhiman am 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
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

R2020a

### Community Treasure Hunt

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

Start Hunting!

Translated by