Exemplo n.º 1
0
    def setUp(self):
        self.X, self.y = load_breast_cancer(return_X_y=True)

        n_clusters = 5
        n_estimators = 3

        # Initialize a set of estimators
        estimators = [KMeans(n_clusters=n_clusters),
                      MiniBatchKMeans(n_clusters=n_clusters),
                      AgglomerativeClustering(n_clusters=n_clusters)]

        self.estimator = ClustererEnsemble(estimators, n_clusters=n_clusters)
        self.estimator.fit(self.X)
Exemplo n.º 2
0
if __name__ == "__main__":
    # Define data file and read X and y
    random_state = 42
    X, y = load_breast_cancer(return_X_y=True)

    n_clusters = 5
    n_estimators = 3

    # Initialize a set of estimators
    estimators = [
        KMeans(n_clusters=n_clusters),
        MiniBatchKMeans(n_clusters=n_clusters),
        AgglomerativeClustering(n_clusters=n_clusters)
    ]

    clf = ClustererEnsemble(estimators, n_clusters=n_clusters)
    clf.fit(X)
    predicted_labels = clf.labels_
    aligned_labels = clf.aligned_labels_

    # Clusterer Ensemble without ininializing a new Class
    original_labels = np.zeros([X.shape[0], n_estimators])

    for i, estimator in enumerate(estimators):
        estimator.fit(X)
        original_labels[:, i] = estimator.labels_

    # Invoke method directly without initialiing a new Class
    labels_by_vote1 = clusterer_ensemble_scores(original_labels, n_estimators,
                                                n_clusters)
    labels_by_vote2, aligned_labels = clusterer_ensemble_scores(