# Path: skmultilearn/cluster/matrix.py
# class MatrixLabelSpaceClusterer(LabelSpaceClustererBase):
#     """Cluster the label space using a scikit-compatible matrix-based clusterer
# 
#     Parameters
#     ----------
#     clusterer : sklearn.base.ClusterMixin
#         a clonable instance of a scikit-compatible clusterer, will be automatically
#         put under :code:`self.clusterer`.
#     pass_input_space : bool (default is False)
#         whether to take :code:`X` into consideration upon clustering,
#         use only if you know that the clusterer can handle two
#         parameters for clustering, will be automatically
#         put under :code:`self.pass_input_space`.
# 
# 
#     Example code for using this clusterer looks like this:
# 
#     .. code-block:: python
# 
#         from sklearn.ensemble import RandomForestClassifier
#         from sklearn.cluster import KMeans
#         from skmultilearn.problem_transform import LabelPowerset
#         from skmultilearn.cluster import MatrixLabelSpaceClusterer
#         from skmultilearn.ensemble import LabelSpacePartitioningClassifier
# 
#         # construct base forest classifier
#         base_classifier = RandomForestClassifier(n_estimators=1030)
# 
#         # setup problem transformation approach with sparse matrices for random forest
#         problem_transform_classifier = LabelPowerset(classifier=base_classifier,
#             require_dense=[False, False])
# 
#         # setup the clusterer
#         clusterer = MatrixLabelSpaceClusterer(clusterer=KMeans(n_clusters=3))
# 
#         # setup the ensemble metaclassifier
#         classifier = LabelSpacePartitioningClassifier(problem_transform_classifier, clusterer)
# 
#         # train
#         classifier.fit(X_train, y_train)
# 
#         # predict
#         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)))
# 
# Path: skmultilearn/tests/classifier_basetest.py
# class ClassifierBaseTest(unittest.TestCase):
#     def get_multilabel_data_for_tests(self, sparsity_indicator):
#         feed_sparse = sparsity_indicator == 'sparse'
# 
#         if feed_sparse:
#             return [(sparse.csr_matrix(EXAMPLE_X), sparse.csr_matrix(EXAMPLE_y))]
#         else:
#             return [(np.matrix(EXAMPLE_X), np.matrix(EXAMPLE_y))]
# 
# 
#     def assertClassifierWorksWithSparsity(self, classifier, sparsity_indicator='sparse'):
#         for X,y in self.get_multilabel_data_for_tests(sparsity_indicator):
#             X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.33, random_state=42)
#             classifier.fit(X_train, y_train)
#             result = classifier.predict(X_test)
#             self.assertEqual(result.shape, y_test.shape)
# 
#     def assertClassifierWorksWithCV(self, classifier):
#         # all the nice stuff is tested here - whether the classifier is
#         # clonable, etc.
#         for X, y in self.get_multilabel_data_for_tests('dense'):
#             n_iterations = 3
#             cv = model_selection.ShuffleSplit(n_splits=n_iterations, test_size=0.5, random_state=0)
# 
#             scores = model_selection.cross_val_score(
#                 classifier, X, y=y, cv=cv, scoring='accuracy')
# 
#             self.assertEqual(len(scores), n_iterations)
# 
#     def assertClassifierPredictsProbabilities(self, classifier, sparsity_indicator='sparse'):
#         for X, y in self.get_multilabel_data_for_tests(sparsity_indicator):
#             X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.33, random_state=42)
#             classifier.fit(X_train, y_train)
#             result = classifier.predict_proba(X_test)
#             result = result.todense()
# 
#             max_value = result.max()
#             min_value = result.min()
# 
#             self.assertEqual(result.shape, (X_test.shape[0], y.shape[1]))
#             self.assertGreaterEqual(np.round(max_value), 0.0)
#             self.assertGreaterEqual(np.round(min_value), 0.0)
#             self.assertLessEqual(np.round(min_value), 1.0)
#             self.assertLessEqual(np.round(max_value), 1.0)


import numpy as np
import scipy.sparse as sp
from sklearn.cluster import KMeans
from skmultilearn.cluster import MatrixLabelSpaceClusterer
from skmultilearn.tests.classifier_basetest import ClassifierBaseTest



def get_matrix_clusterers(cluster_count=3):
    base_clusterers = [KMeans(cluster_count)]
    for base_clusterer in base_clusterers:
        yield MatrixLabelSpaceClusterer(base_clusterer, False)

class MatrixLabelSpaceClustererTests(ClassifierBaseTest):

    def test_actually_works_on_proper_params(self):

# Path: skmultilearn/cluster/matrix.py
# class MatrixLabelSpaceClusterer(LabelSpaceClustererBase):
#     """Cluster the label space using a scikit-compatible matrix-based clusterer
# 
#     Parameters
#     ----------
#     clusterer : sklearn.base.ClusterMixin
#         a clonable instance of a scikit-compatible clusterer, will be automatically
#         put under :code:`self.clusterer`.
#     pass_input_space : bool (default is False)
#         whether to take :code:`X` into consideration upon clustering,
#         use only if you know that the clusterer can handle two
#         parameters for clustering, will be automatically
#         put under :code:`self.pass_input_space`.
# 
# 
#     Example code for using this clusterer looks like this:
# 
#     .. code-block:: python
# 
#         from sklearn.ensemble import RandomForestClassifier
#         from sklearn.cluster import KMeans
#         from skmultilearn.problem_transform import LabelPowerset
#         from skmultilearn.cluster import MatrixLabelSpaceClusterer
#         from skmultilearn.ensemble import LabelSpacePartitioningClassifier
# 
#         # construct base forest classifier
#         base_classifier = RandomForestClassifier(n_estimators=1030)
# 
#         # setup problem transformation approach with sparse matrices for random forest
#         problem_transform_classifier = LabelPowerset(classifier=base_classifier,
#             require_dense=[False, False])
# 
#         # setup the clusterer
#         clusterer = MatrixLabelSpaceClusterer(clusterer=KMeans(n_clusters=3))
# 
#         # setup the ensemble metaclassifier
#         classifier = LabelSpacePartitioningClassifier(problem_transform_classifier, clusterer)
# 
#         # train
#         classifier.fit(X_train, y_train)
# 
#         # predict
#         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)))
# 
# Path: skmultilearn/tests/classifier_basetest.py
# class ClassifierBaseTest(unittest.TestCase):
#     def get_multilabel_data_for_tests(self, sparsity_indicator):
#         feed_sparse = sparsity_indicator == 'sparse'
# 
#         if feed_sparse:
#             return [(sparse.csr_matrix(EXAMPLE_X), sparse.csr_matrix(EXAMPLE_y))]
#         else:
#             return [(np.matrix(EXAMPLE_X), np.matrix(EXAMPLE_y))]
# 
# 
#     def assertClassifierWorksWithSparsity(self, classifier, sparsity_indicator='sparse'):
#         for X,y in self.get_multilabel_data_for_tests(sparsity_indicator):
#             X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.33, random_state=42)
#             classifier.fit(X_train, y_train)
#             result = classifier.predict(X_test)
#             self.assertEqual(result.shape, y_test.shape)
# 
#     def assertClassifierWorksWithCV(self, classifier):
#         # all the nice stuff is tested here - whether the classifier is
#         # clonable, etc.
#         for X, y in self.get_multilabel_data_for_tests('dense'):
#             n_iterations = 3
#             cv = model_selection.ShuffleSplit(n_splits=n_iterations, test_size=0.5, random_state=0)
# 
#             scores = model_selection.cross_val_score(
#                 classifier, X, y=y, cv=cv, scoring='accuracy')
# 
#             self.assertEqual(len(scores), n_iterations)
# 
#     def assertClassifierPredictsProbabilities(self, classifier, sparsity_indicator='sparse'):
#         for X, y in self.get_multilabel_data_for_tests(sparsity_indicator):
#             X_train, X_test, y_train, y_test = model_selection.train_test_split(X, y, test_size=0.33, random_state=42)
#             classifier.fit(X_train, y_train)
#             result = classifier.predict_proba(X_test)
#             result = result.todense()
# 
#             max_value = result.max()
#             min_value = result.min()
# 
#             self.assertEqual(result.shape, (X_test.shape[0], y.shape[1]))
#             self.assertGreaterEqual(np.round(max_value), 0.0)
#             self.assertGreaterEqual(np.round(min_value), 0.0)
#             self.assertLessEqual(np.round(min_value), 1.0)
#             self.assertLessEqual(np.round(max_value), 1.0)


# Path: skmultilearn/cluster/tests/test_matrix.py
import numpy as np
import scipy.sparse as sp
from sklearn.cluster import KMeans
from skmultilearn.cluster import MatrixLabelSpaceClusterer
from skmultilearn.tests.classifier_basetest import ClassifierBaseTest




def get_matrix_clusterers(cluster_count=3):
    base_clusterers = [KMeans(cluster_count)]
    for base_clusterer in base_clusterers:
        yield MatrixLabelSpaceClusterer(base_clusterer, False)

class MatrixLabelSpaceClustererTests(ClassifierBaseTest):

    def test_actually_works_on_proper_params(self):

        for X, y in self.get_multilabel_data_for_tests('sparse'):