def cluster(X, fig, ax):

    # Setup Affinity Propagation
    af = AffinityPropagation(preference=-50).fit(X)
    cluster_centers_indices = af.cluster_centers_indices_
    labels = af.labels_
    no_clusters = len(cluster_centers_indices)
    print('Estimated number of clusters: %d' % no_clusters)
    plot_columns = plotable(X)
    centers = plotable(X[cluster_centers_indices])
    plot1(no_clusters, labels, plot_columns, centers, ax)
    return labels, no_clusters
Esempio n. 2
0
def cluster(X, fig, ax):

    num_clusters = int(input("Enter Number of cluster:"))

    kmeans_model = KMeans(n_clusters=num_clusters, random_state=1, n_init=10)
    kmeans_model.fit(X)
    labels = kmeans_model.labels_
    # clusters = {i: np.where(labels == i)[0] for i in range(kmeans_model.n_clusters)}

    plot_columns = plotable(X)
    centers = plotable(kmeans_model.cluster_centers_)

    plot1(num_clusters, labels, plot_columns, centers, ax)
    return labels, num_clusters
Esempio n. 3
0
def cluster(X, fig, ax):

    num_clusters = int(input("Enter Number of cluster:"))

    minibatch_model = MiniBatchKMeans(n_clusters=num_clusters,
                                      init='k-means++',
                                      n_init=1,
                                      init_size=1000,
                                      batch_size=1000)
    minibatch_model.fit(X)
    labels = minibatch_model.labels_
    # clusters = {i: np.where(labels == i)[0] for i in range(minibatch_model.n_clusters)}

    plot_columns = plotable(X)
    centers = plotable(minibatch_model.cluster_centers_)

    plot1(num_clusters, labels, plot_columns, centers, ax)
    return labels, num_clusters
def cluster(X,fig,ax):

    # Required for fuzzy cmeans(X is (num_feature,num_sample))
    X = X.T
    # print("Input shape:",X.shape)
    num_cluster = int(input("Enter Number of cluster:"))

    cntr, u_orig, _, _, _, _, _ = fuzz.cluster.cmeans(
        X, num_cluster, 2, error=0.005, maxiter=1000)

    X =X.T
    plot_columns = plotable(X)
    plot_centers = plotable(cntr)

    # Labels for each sample
    cluster_membership = np.argmax(u_orig, axis=0)
    # Clusters
    # clusters = {i: np.where(cluster_membership == i)[0] for i in range(num_cluster)}
    plot1(num_cluster, cluster_membership, plot_columns, plot_centers, ax)

    return cluster_membership, num_cluster
Esempio n. 5
0
def cluster(X, fig, ax):
    labels = ''
    num_clusters = int(input("Enter Number of cluster:"))
    knn_graph = kneighbors_graph(X, 30, include_self=False)
    connectivity = (None, knn_graph)[0]
    linkage = 'complete'
    model = AgglomerativeClustering(linkage=linkage,
                                    connectivity=connectivity,
                                    n_clusters=num_clusters)
    model.fit(X)
    labels = model.labels_
    plot_columns = plotable(X)
    centers = None
    plot1(num_clusters, labels, plot_columns, centers, ax)
    return labels, num_clusters