Ejemplo n.º 1
0
def main():
    # Load the dataset
    X, y = datasets.make_moons(n_samples=300, noise=0.08, shuffle=False)
    print(X.shape)
    # Cluster the data using Agnes
    agnes_cluster = AGNES(10)
    centroids, labels = agnes_cluster.fit(X)
    p = Plot()
    p.plot_in_2d(X, labels, "Preds")
    p.plot_in_2d(X, y, "Actual")
def main():
    # Load the dataset
    X, y = datasets.make_blobs()

    # Cluster the data
    clf = GaussianMixtureModel(k=3)
    y_pred = clf.predict(X)

    p = Plot()
    p.plot_in_2d(X, y_pred, title="GMM Clustering")
    p.plot_in_2d(X, y, title="Actual Clustering")
Ejemplo n.º 3
0
def main():
    # Load the dataset
    X , y = datasets.make_moons(n_samples=300, noise=0.08, shuffle=False)

    # Cluster the data using DBSCAN
    kmedoid_cluster = KMediod(X , 2 , 1)
    medoids , labels = kmedoid_cluster.fit(10, max_steps=1000)
    print(medoids , labels)
    p = Plot()
    p.plot_in_2d(X , labels , "Preds")
    p.plot_in_2d(X , y , "Actual")
Ejemplo n.º 4
0
def main():
    # Load the dataset
    X, y = datasets.make_moons(n_samples=300, noise=0.1, shuffle=False)

    # Cluster the data using DBSCAN
    clf = DBSCAN(eps=0.17, min_samples=5)
    y_pred = clf.predict(X)

    # Project the data onto the 2 primary principal components
    p = Plot()
    p.plot_in_2d(X, y_pred, title="DBSCAN")
    p.plot_in_2d(X, y, title="Actual Clustering")
Ejemplo n.º 5
0
def main():
    # Load the dataset
    X, y = datasets.make_moons(n_samples=300, noise=0.08, shuffle=False)

    # Cluster the data using DBSCAN
    clf = DBSCAN(eps=0.17, min_samples=5)
    y_pred = clf.predict(X)

    # Project the data onto the 2 primary principal components
    p = Plot()
    p.plot_in_2d(X, y_pred, title="DBSCAN")
    p.plot_in_2d(X, y, title="Actual Clustering")
def main():
    # Load the dataset
    X, y = datasets.make_blobs()

    # Cluster the data using K-Medoids
    clf = PAM(k=3)
    y_pred = clf.predict(X)

    # Project the data onto the 2 primary principal components
    p = Plot()
    p.plot_in_2d(X, y_pred, title="PAM Clustering")
    p.plot_in_2d(X, y, title="Actual Clustering")
Ejemplo n.º 7
0
def main():
    # Load the dataset
    X, y = datasets.make_blobs()

    # Cluster the data using K-Means
    clf = KMeans(k=3)
    y_pred = clf.predict(X)

    # Project the data onto the 2 primary principal components
    p = Plot()
    p.plot_in_2d(X, y_pred, title="K-Means Clustering")
    p.plot_in_2d(X, y, title="Actual Clustering")
                              self.responsibilities[-2])
        return diff <= self.tolerance

    def predict(self, X):
        """ Run GMM and return the cluster indices """
        # Initialize the gaussians randomly
        self._init_random_gaussians(X)
        # Run EM until convergence or for max iterations
        for _ in range(self.max_iterations):
            self._expectation(X)
            self._maximization(X)
            # Check convergence
            if self._converged():
                break
        # Make new assignments and return them
        self._expectation(X)
        # Assign samples to cluster that has largest probability
        sample_assignments = self.responsibility.argmax(axis=1)
        return sample_assignments


if __name__ == '__main__':
    # Load the dataset
    X, y = datasets.make_blobs()
    # Cluster the data
    clf = GaussianMixtureModel(k=3)
    y_pred = clf.predict(X)
    p = Plot()
    p.plot_in_2d(X, y_pred, title="GMM Clustering")
    p.plot_in_2d(X, y, title="Actual Clustering")