kmean with dtw distance

18 ビュー (過去 30 日間)
Vincent Derozier
Vincent Derozier 2020 年 9 月 7 日
回答済み: Anmol Dhiman 2020 年 9 月 16 日
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 Center および File ExchangeStatistics 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