Demo entry 6364722



Submitted by anonymous on May 16, 2017 at 21:03
Language: Python. Code size: 1.0 kB.

        import numpy as np
        import matplotlib.pyplot as plt
        import StarClustering as sc
        seed = 97
        def creat_random_clusters(n_sample, n_features, n_clusters, scale=0.2):
            mu = np.random.normal(0, 7*scale, size=(n_clusters, n_features))
            labels = np.array([])
            fullset = np.zeros((n_sample, n_features))
            n_cut = int(n_sample/n_clusters)
            for k in range(n_clusters):
                fullset[(k)*n_cut:(k+1)*n_cut] = np.random.normal(mu[k], scale=scale, size=(n_cut,n_features))
                labels = np.append(labels, np.full(n_cut, k))
            return fullset, labels

        n_sample = 9000
        n_features = 5
        n_clusters = 4
        fullset, labels_ref = creat_random_clusters(n_sample, n_features, n_clusters)
        RESULTS = sc.kmeans(fullset, n_clusters=3, RandState=seed)
        corner_compare.corner(fullset, np.unique(labels_0),  RESULTS[0])

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).