Strange error in using kmedoids function
显示 更早的评论
hi, thanks for your attention.
I'm trying to apply the kmedoids function to my dataset to cluster it into three subgroups. I set two additive parameters to the function by imposing "Algorithm" equal to "pam" and imposing a "Distance" defined by me (the Jensen – Shannon distance).
The command I run in my script is the following: kmedoids(X, 3, 'Algorithm', 'pam', 'Distance', @JSD) where X is the matrix, and JSD if the distance function difined by me. I ran the algorithm for different X data arrays and it works fine.
Only in the last run, with a new data matrix X, does it return the following error, and I don't know where the problem may be:
Error using datasample (line 123)
The value of Weights must not be complex.
Error in kmedoids>initialFunc/kplus (line 486)
[initialMedoids(ii,:), index(ii)] = datasample(S,X,1,1,'Replace',false,...
Error in internal.stats.kmedoidsPAM (line 55)
[~, medoidIndex] = initialize(X,k,S,rep);
Error in kmedoids>@(rep,S)internal.stats.kmedoidsPAM(rep,S,X,k,distObj,initialize,maxIterations,xDist,display,usePool) (line 547)
fcnHandle = @(rep,S) internal.stats.kmedoidsPAM(rep,S,X,k,distObj,initialize,maxIterations,xDist,display,usePool);
Error in internal.stats.parallel.smartForReduce (line 136)
reduce = loopbody(iter, S);
Error in kmedoids (line 411)
ClusterBest = internal.stats.parallel.smartForReduce(...
回答(1 个)
Cris LaPierre
2020-3-28
编辑:Cris LaPierre
2020-3-28
The top error is likely the one you can do something about (Error using datasample (line 123)). Is the indicated code something you wrote?
[initialMedoids(ii,:), index(ii)] = datasample(S,X,1,1,'Replace',false,...
The weights are complex, which is not allowed. Review your calculation of weights.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!