'Transforms the label sets with a given mapping
Parameters
y : iterable of iterables
class_mapping : Mapping
Maps from label to column index in label indicator matrix
Returns
y_indicator : sparse CSR matrix, shape (n_samples, n_classes)
Label indicator matrix'

def _transform(self, y, class_mapping):

    indices = array.array('i')
    indptr = array.array('i', [0])
    for labels in y:
        indices.extend(set((class_mapping[label] for label in labels)))
        indptr.append(len(indices))
    data = np.ones(len(indices), dtype=int)
    return sp.csr_matrix((data, indices, indptr), shape=((len(indptr) - 1), len(class_mapping)))
