def METHOD_NAME(self, X, init_params=True):
    """Learn cluster centroids from training data.
    Called in self.fit
    """
    n_samples = X.shape[0]
    if init_params:
        self.iterations_ = 0
        # initialize centroids
        rgen = np.random.RandomState(self.random_seed)
        idx = rgen.choice(n_samples, self.k, replace=False)
        self.centroids_ = X[idx]
    for _ in range(self.max_iter):
        # assign samples to cluster centroids
        self.clusters_ = {i: [] for i in range(self.k)}
        for sample_idx, cluster_idx in enumerate(
            self._get_cluster_idx(X=X, centroids=self.centroids_)
        ):
            self.clusters_[cluster_idx].append(sample_idx)
        # recompute centroids
        new_centroids = np.array(
            [
                np.mean(X[self.clusters_[k]], axis=0)
                for k in sorted(self.clusters_.keys())
            ]
        )
        # stop if cluster assignment doesn't change
        if np.allclose(
            self.centroids_,
            new_centroids,
            rtol=self.convergence_tolerance,
            atol=1e-08,
            equal_nan=False,
        ):
            break
        else:
            self.centroids_ = new_centroids
        self.iterations_ += 1
        if self.print_progress:
            self._print_progress(iteration=self.iterations_, n_iter=self.max_iter)
    return self