# Path: skmultilearn/cluster/base.py
# class LabelSpaceClustererBase(BaseEstimator):
#     """An abstract base class for Label Space clustering
# 
#     Inherit it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#     """
# 
#     def __init__(self):
#         super(LabelSpaceClustererBase, self).__init__()
# 
#     def fit_predict(self, X, y):
#         """ Abstract method for clustering label space
# 
#         Implement it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#         Raises
#         ------
#         NotImplementedError
#             this is an abstract method
#         """
#         raise NotImplementedError("LabelSpaceClustererBase::fit_predict()")
# 
# Path: skmultilearn/cluster/helpers.py
# def _membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of int
#         community membership i.e. vertex/label `i` is in community `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_id in enumerate(membership_vector):
#         list_of_members[community_id].append(vertex_id)
#     return list_of_members


import numpy as np
from .base import LabelSpaceClustererBase
from .helpers import _membership_to_list_of_communities
        predictions = classifier.predict(X_test)
    """

    def __init__(self, clusterer=None, pass_input_space=False):
        super(MatrixLabelSpaceClusterer, self).__init__()

        self.clusterer = clusterer
        self.pass_input_space = pass_input_space

    def fit_predict(self, X, y):
        """Clusters the output space

        The clusterer's :code:`fit_predict` method is executed
        on either X and y.T vectors (if :code:`self.pass_input_space` is true)
        or just y.T to detect clusters of labels.

        The transposition of label space is used to align with
        the format expected by scikit-learn classifiers, i.e. we cluster
        labels with label assignment vectors as samples.

        Returns
        -------
        arrray of arrays of label indexes (numpy.ndarray)
            label space division, each sublist represents labels that are in that community
        """

        if self.pass_input_space:
            result = self.clusterer.fit_predict(X, y.transpose())
        else:
            result = self.clusterer.fit_predict(y.transpose())

# Path: skmultilearn/cluster/base.py
# class LabelSpaceClustererBase(BaseEstimator):
#     """An abstract base class for Label Space clustering
# 
#     Inherit it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#     """
# 
#     def __init__(self):
#         super(LabelSpaceClustererBase, self).__init__()
# 
#     def fit_predict(self, X, y):
#         """ Abstract method for clustering label space
# 
#         Implement it in your classifier according to`developer guide <../developer.ipynb>`_.
# 
#         Raises
#         ------
#         NotImplementedError
#             this is an abstract method
#         """
#         raise NotImplementedError("LabelSpaceClustererBase::fit_predict()")
# 
# Path: skmultilearn/cluster/helpers.py
# def _membership_to_list_of_communities(membership_vector, size):
#     """Convert membership vector to list of lists of vertices in each community
# 
#     Parameters
#     ----------
#     membership_vector : list of int
#         community membership i.e. vertex/label `i` is in community `membership_vector[i]`
#     size : int
#         the number of communities present in the membership vector
# 
# 
#     Returns
#     -------
#     list_of_members : list of lists of int
#         list of lists of vertex/label ids in each community per community
#     """
#     list_of_members = [[] for _ in range(size)]
#     for vertex_id, community_id in enumerate(membership_vector):
#         list_of_members[community_id].append(vertex_id)
#     return list_of_members


# Path: skmultilearn/cluster/matrix.py
import numpy as np
from .base import LabelSpaceClustererBase
from .helpers import _membership_to_list_of_communities

        predictions = classifier.predict(X_test)
    """

    def __init__(self, clusterer=None, pass_input_space=False):
        super(MatrixLabelSpaceClusterer, self).__init__()

        self.clusterer = clusterer
        self.pass_input_space = pass_input_space

    def fit_predict(self, X, y):
        """Clusters the output space

        The clusterer's :code:`fit_predict` method is executed
        on either X and y.T vectors (if :code:`self.pass_input_space` is true)
        or just y.T to detect clusters of labels.

        The transposition of label space is used to align with
        the format expected by scikit-learn classifiers, i.e. we cluster
        labels with label assignment vectors as samples.

        Returns
        -------
        arrray of arrays of label indexes (numpy.ndarray)
            label space division, each sublist represents labels that are in that community
        """

        if self.pass_input_space:
            result = self.clusterer.fit_predict(X, y.transpose())
        else:
            result = self.clusterer.fit_predict(y.transpose())

        return np.array(_membership_to_list_of_communities(result, 1 + max(result)))