implementing k means algorithm on spike sorting data
Afficher commentaires plus anciens
Hi there, I am trying to implemement my own K means function without using the unbuilt function 'kmeans'.
I started with some complex waveform data and reduced the dimensionality to 2 PC and plotted on a scatter, 3 distinct clusters emerge.
to do k means first i set random centroids within the range of the data - e.g.
k=3
%state the number of clusters%
centroids = min(wav_pca) + (max(wav_pca)-min(wav_pca)).* rand(k,1) %create random centroids in the range of test data%
scatter(wav_pca(:,1),wav_pca(:,2))
hold on
scatter(centroids(:,1),centroids(:,2),'x');
hold off
this gives me starting centroids - howevr i don't this the distribution is as random as i'd like.
then I have to compute the euclidean distance from each point to a centroid and assign it to the one with the shortest distance
for j=1:k
for i=1:length(wav_pca)
distance=sqrt( (centroids(j,1)- wav_pca(i,1))^2 + (centroids(j,2)- wav_pca(i,2)^2) )
end
end
for this I tried to use this for loop but it's not creating the matrix of distances that I need.
then each point must be assigned to it's closest centroid, giving it a cluster ID
the cluster centroids need to be recomputed as an average of all the assigned points and the points reassigned, this needs to be iterated though until the assignments change and I am unsure how to do this.
thanks for all that you can help with, if you need any more info let me know, and apologies for being new to matlab.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!