@@ -0,0 +1,1095 @@
+import numpy as np%0A%0Afrom sklearn.metrics.pairwise import pairwise_distances%0Afrom sklearn.base import BaseEstimator, ClusterMixin, TransformerMixin%0A%0Aclass ConstrainedKMeans(BaseEstimator, ClusterMixin, TransformerMixin):%0A%0A    def __init__(self, n_clusters=8):%0A        self.n_clusters = n_clusters%0A%0A    def fit(self, X, y=None, must_link=set(), cannot_link=set()):%0A        assert type(X).__name__ == 'ndarray', %22X must be a ndarray%22%0A        assert X.shape%5B0%5D %3E= self.n_clusters, %22X can't have less objects than n_clusters%22%0A%0A        # Initialize cluster centers%0A        n_samples = X.shape%5B0%5D%0A        samples_idx = np.random.choice(range(n_samples), self.n_clusters, replace=False)%0A        centroids = map(lambda i: X%5Bi%5D, samples_idx)%0A%0A        # ...%0A%0A    # TODO: Implement _violate_constrains%0A    def _violate_constraints(instance, cluster, must_link, cannot_link):%0A        return False%0A%0A%0Aif __name__ == '__main__':%0A    c = ConstrainedKMeans(n_clusters=3)%0A    X = np.array(%5B%0A        %5B0%5D,%0A        %5B1%5D,%0A        %5B2%5D,%0A        %5B3%5D,%0A        %5B4%5D,%0A        %5B5%5D,%0A        %5B6%5D,%0A        %5B7%5D,%0A    %5D)%0A    c.fit(X)

Add ContrainedKMeans class (WIP)