Exemplo n.º 1
0
def main():
  datos=clusterInCluster(130)
  datos=datos[:,range(0,2)]
  [colores, grafo]=clusterJerarquico(singleLinkage,datos,2)
  qApp = QtGui.QApplication(sys.argv)
  aw = ApplicationWindow(colores,grafo)
  aw.setWindowTitle("%s" % progname)
  aw.show()
  return qApp.exec_()                    
Exemplo n.º 2
0
            axes[i, j].plot(data[labels == 0,i],data[labels == 0,j], 'ro', ms=5)
            axes[i, j].plot(data[labels == 1,i],data[labels == 1,j], 'bo', ms=5)
            axes[i, j].plot(data[labels == 2,i],data[labels == 2,j], 'go', ms=5)
    
    (fig, axes) = plt.subplots(nCols, nCols, figsize=(fig_size, fig_size));
    fig.suptitle('Found')
    for i in range(0, nCols):
        for j in range(0, nCols):
            if (i == j):
                continue
            axes[i, j].plot(data[clusters[0],i],data[clusters[0],j], 'ro', ms=5)
            axes[i, j].plot(data[clusters[1],i],data[clusters[1],j], 'bo', ms=5)
            axes[i, j].plot(data[clusters[2],i],data[clusters[2],j], 'go', ms=5)
else:            
    N = 100
    data = np.array(clusterInCluster(N));
    original_clusters = data[:,2]
    data = data[:,0:2]
    
    file_path = 'skin_points.csv'
    df=pd.read_csv(file_path, sep=',',header=None)
    #data = df.values[:, 0:2]
    data  = df.values
    data = data[0:data.shape[0]:50,:].astype(np.float64)
    
    clusters = functions[selected_func](data, k, euclidean_dist);      
    
    plt.plot(data[clusters[0],0],data[clusters[0],1], 'ro', ms=5)
    plt.plot(data[clusters[1],0],data[clusters[1],1], 'bo', ms=5)
    if k > 1:
        plt.plot(data[clusters[2],0],data[clusters[2],1], 'go', ms=5)
Exemplo n.º 3
0
Created on Mon Jul  6 06:27:33 2015

Asumo que fue llamado configurarPath antes en el entorno
"""



from  clusterincluster import clusterInCluster
from  scipy.spatial.distance import pdist
from  scipy.cluster.hierarchy import linkage,dendrogram,fcluster
from matplotlib.pyplot import plot,figure
import matplotlib.pyplot as plt
from scipy import indices
import numpy

datos = clusterInCluster()
datos = datos[:,range(0,2)]
#Calculo la matriz de distancias
distancias =  pdist(datos,metric='euclidean')
#Tomo el metodo de single linkage
dendro     = linkage(distancias,method='single')
#Ploteo el dendrograma
dendrogram(dendro)
#Utilizo el valor 1.5 para cortar el dendrograma
clusters = fcluster(dendro,1,criterion='distance')

#Obtengo los indices de os patrones pertenecientes a cada cluster
indClus1 =numpy.where(clusters ==1)
indClus2 =numpy.where(clusters ==2)
#Los dibujo
figure()
Exemplo n.º 4
0
            clus.remove(v2)
            clus.append(clusNuevo)
        return clus    
        
def single_link_dist(clus_i, clus_j, datos):
      #dmin= sys.maxint
      dmin= sys.maxsize
      for i in clus_i:
          for j in clus_j:
              d = norm(datos[i,:] - datos[j,:])
              if (dmin > d):
                  dmin=d
      return dmin
     
     
     
#datos = [[random.randint(0,100) for x in range(0,5)] for x in range(0,5)]
#datos = [[random.randint(0,100) for x in range(0,2)] for x in range(0,100)]
#datos = array(datos)     
#print(datos)

datos = clusterInCluster(N=70);
clusters=datos[:,2]
datos=datos[:,0:2]
k = 2    

clusters = single_linkage(datos, k)
pt.plot(datos[clusters[0],0],datos[clusters[0],1], 'r*', ms=10)
pt.plot(datos[clusters[1],0],datos[clusters[1],1], 'b*', ms=10)