kmean with dtw distance

8 次查看(过去 30 天)
Vincent Derozier
Vincent Derozier 2020-9-7
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)));

回答(1 个)

Anmol Dhiman
Anmol Dhiman 2020-9-16
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

类别

Help CenterFile Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by