def predict(self, X):
check_rdd(X, (np.ndarray, sp.spmatrix))<EOL>if hasattr(self, '<STR_LIT>'):<EOL><INDENT>if isinstance(X, ArrayRDD):<EOL><INDENT>X = X.unblock()<EOL><DEDENT>return X.map(lambda x: self._mllib_model.predict(x))<EOL><DEDENT>else:<EOL><INDENT>rdd = X.map(lambda X: super(SparkKMeans, self).predict(X))<EOL>return ArrayRDD(rdd)<EOL><DEDENT>
Predict the closest cluster each sample in X belongs to.

        In the vector quantization literature, `cluster_centers_` is called
        the code book and each value returned by `predict` is the index of
        the closest code in the code book.

        Parameters
        ----------
        X : ArrayRDD containing array-like, sparse matrix
            New data to predict.

        Returns
        -------
        labels : ArrayRDD with predictions
            Index of the cluster each sample belongs to.