Skip to content

Instantly share code, notes, and snippets.

@nhasbun
Last active May 19, 2016 04:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhasbun/48b8157e5bd296a1a93f86994cc4a3eb to your computer and use it in GitHub Desktop.
Save nhasbun/48b8157e5bd296a1a93f86994cc4a3eb to your computer and use it in GitHub Desktop.
Classification using KMeans clustering
function [resultado]=clasificar(muestra, centroides)
%%
% muestra de n X no_caracteristicas
% centroides de no_clases X no_caracteristicas
%% Clasificacion de muestras
% segun clustering usando KMEANS.
% Se requiere centroides eiquetados previamente
% es decir, un resultado 1 equivale a la clase 1
largo =length(muestra);
resultado =zeros(1, largo);
no_centroides=size(centroides, 1);
for i=1:largo
distancia=1;
% distancia maxima, muestras normalizadas
for j=1:no_centroides
distancia_temp=abs(muestra(i)-centroides(j, i));
if(distancia_temp<distancia)
distancia=distancia_temp;
resultado(i)=j;
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment