MATLAB Answers

Strange error in using kmedoids function

3 views (last 30 days)
Alessandro Fuschi
Alessandro Fuschi on 27 Mar 2020
Edited: Cris LaPierre on 28 Mar 2020
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(...

  0 Comments

Sign in to comment.

Answers (1)

Cris LaPierre
Cris LaPierre on 28 Mar 2020
Edited: Cris LaPierre on 28 Mar 2020
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.

  0 Comments

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019b