필터 지우기
필터 지우기

kmean with dtw distance

조회 수: 12 (최근 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 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