# Path: skmultilearn/cluster/fixed.py
# class FixedLabelSpaceClusterer(LabelSpaceClustererBase):
#     """Return a fixed label space partition
# 
#     This clusterer takes a predefined fixed ``clustering`` of the label space and returns it in fit_predict as the label
#     space division. This is useful for employing expert knowledge about label space division or partitions in ensemble
#     classifiers such as: :class:`~skmultilearn.ensemble.LabelSpacePartitioningClassifier` or
#     :class:`~skmultilearn.ensemble.MajorityVotingClassifier`.
# 
#     Parameters
#     ----------
#     clusters : array of arrays of int
#         provided partition of the label space in the for of numpy array of
#         numpy arrays of indexes for each partition, ex. ``[[0,1],[2,3]]``
# 
# 
#     An example use of the fixed clusterer with a label partitioning classifier to train randomforests for a set of
#     subproblems defined upon expert knowledge:
# 
#     .. code :: python
# 
#         from skmultilearn.ensemble import LabelSpacePartitioningClassifier
#         from skmultilearn.cluster import FixedLabelSpaceClusterer
#         from skmultilearn.problem_transform import LabelPowerset
#         from sklearn.ensemble import RandomForestClassifier
# 
#         classifier = LabelSpacePartitioningClassifier(
#             classifier = LabelPowerset(
#                 classifier=RandomForestClassifier(n_estimators=100),
#                 require_dense = [False, True]
#             ),
#             require_dense = [True, True],
#             clusterer = FixedLabelSpaceClusterer(clustering=[[1,2,3], [0,4]])
#         )
# 
#         # train
#         classifier.fit(X_train, y_train)
# 
#         # predict
#         predictions = classifier.predict(X_test)
# 
#     """
# 
#     def __init__(self, clusters=None):
#         super(FixedLabelSpaceClusterer, self).__init__()
# 
#         self.clusters = clusters
# 
#     def fit_predict(self, X, y):
#         """Returns the provided label space division
# 
#         Parameters
#         ----------
#         X : None
#             currently unused, left for scikit compatibility
#         y : scipy.sparse
#             label space of shape :code:`(n_samples, n_labels)`
# 
#         Returns
#         -------
#         arrray of arrays of label indexes (numpy.ndarray)
#             label space division, each sublist represents labels that are in that community
#         """
# 
#         return self.clusters
# 
# 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 scipy.sparse as sp
import numpy as np
from skmultilearn.cluster import FixedLabelSpaceClusterer
from skmultilearn.tests.classifier_basetest import ClassifierBaseTest



def get_fixed_clusterers():
    cluster_cases = [
        # non-overlapping
        [[1,2], [0, 3, 4]],
        # overlapping
        [[1,2,3], [0,3,4]]
    ]
    for clusters in cluster_cases:
        clusters = np.array(clusters)

# Path: skmultilearn/cluster/fixed.py
# class FixedLabelSpaceClusterer(LabelSpaceClustererBase):
#     """Return a fixed label space partition
# 
#     This clusterer takes a predefined fixed ``clustering`` of the label space and returns it in fit_predict as the label
#     space division. This is useful for employing expert knowledge about label space division or partitions in ensemble
#     classifiers such as: :class:`~skmultilearn.ensemble.LabelSpacePartitioningClassifier` or
#     :class:`~skmultilearn.ensemble.MajorityVotingClassifier`.
# 
#     Parameters
#     ----------
#     clusters : array of arrays of int
#         provided partition of the label space in the for of numpy array of
#         numpy arrays of indexes for each partition, ex. ``[[0,1],[2,3]]``
# 
# 
#     An example use of the fixed clusterer with a label partitioning classifier to train randomforests for a set of
#     subproblems defined upon expert knowledge:
# 
#     .. code :: python
# 
#         from skmultilearn.ensemble import LabelSpacePartitioningClassifier
#         from skmultilearn.cluster import FixedLabelSpaceClusterer
#         from skmultilearn.problem_transform import LabelPowerset
#         from sklearn.ensemble import RandomForestClassifier
# 
#         classifier = LabelSpacePartitioningClassifier(
#             classifier = LabelPowerset(
#                 classifier=RandomForestClassifier(n_estimators=100),
#                 require_dense = [False, True]
#             ),
#             require_dense = [True, True],
#             clusterer = FixedLabelSpaceClusterer(clustering=[[1,2,3], [0,4]])
#         )
# 
#         # train
#         classifier.fit(X_train, y_train)
# 
#         # predict
#         predictions = classifier.predict(X_test)
# 
#     """
# 
#     def __init__(self, clusters=None):
#         super(FixedLabelSpaceClusterer, self).__init__()
# 
#         self.clusters = clusters
# 
#     def fit_predict(self, X, y):
#         """Returns the provided label space division
# 
#         Parameters
#         ----------
#         X : None
#             currently unused, left for scikit compatibility
#         y : scipy.sparse
#             label space of shape :code:`(n_samples, n_labels)`
# 
#         Returns
#         -------
#         arrray of arrays of label indexes (numpy.ndarray)
#             label space division, each sublist represents labels that are in that community
#         """
# 
#         return self.clusters
# 
# 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_fixed.py
import scipy.sparse as sp
import numpy as np
from skmultilearn.cluster import FixedLabelSpaceClusterer
from skmultilearn.tests.classifier_basetest import ClassifierBaseTest




def get_fixed_clusterers():
    cluster_cases = [
        # non-overlapping
        [[1,2], [0, 3, 4]],
        # overlapping
        [[1,2,3], [0,3,4]]
    ]
    for clusters in cluster_cases:
        clusters = np.array(clusters)

        yield clusters, FixedLabelSpaceClusterer(clusters=clusters)