human
Complete this python program:
def make_multilabel_classification(n_samples=100, n_features=20, n_classes=5, n_labels=2, length=50, allow_unlabeled=True, sparse=False, return_indicator='dense', return_distributions=False, random_state=None):
assistant
#Here is the Python code you requested.

    """Generate a random multilabel classification problem.
    For each sample, the generative process is:
    - pick the number of labels: n ~ Poisson(n_labels)
    - n times, choose a class c: c ~ Multinomial(theta)
    - pick the document length: k ~ Poisson(length)
    - k times, choose a word: w ~ Multinomial(theta_c)
    In the above process, rejection sampling is used to make sure that
    n is never zero or more than `n_classes`, and that the document length
    is never zero. Likewise, we reject classes which have already been chosen.
    Read more in the :ref:`User Guide <sample_generators>`.
    Parameters
    n_samples : int, optional (default=100)
    The number of samples.
    n_features : int, optional (default=20)
    The total number of features.
    n_classes : int, optional (default=5)
    The number of classes of the classification problem.
    n_labels : int, optional (default=2)
    The average number of labels per instance. More precisely, the number
    of labels per sample is drawn from a Poisson distribution with
    ``n_labels`` as its expected value, but samples are bounded (using
    rejection sampling) by ``n_classes``, and must be nonzero if
    ``allow_unlabeled`` is False.
    length : int, optional (default=50)
    The sum of the features (number of words if documents) is drawn from
    a Poisson distribution with this expected value.
    allow_unlabeled : bool, optional (default=True)
    If ``True``, some instances might not belong to any class.
    sparse : bool, optional (default=False)
    If ``True``, return a sparse feature matrix
    .. versionadded:: 0.17
    parameter to allow *sparse* output.
    return_indicator : \dense\ (default) | \sparse\ | False
    If ``dense`` return ``Y`` in the dense binary indicator format. If
    ``\sparse\`` return ``Y`` in the sparse binary indicator format.
    ``False`` returns a list of lists of labels.
    return_distributions : bool, optional (default=False)
    If ``True``, return the prior class probability and conditional
   ..."""
    generator = check_random_state(random_state)
    p_c = generator.rand(n_classes)
    p_c /= p_c.sum()
    cumulative_p_c = np.cumsum(p_c)
    p_w_c = generator.rand(n_features, n_classes)
    p_w_c /= np.sum(p_w_c, axis=0)
    def sample_example():
        (_, n_classes) = p_w_c.shape
        y_size = (n_classes + 1)
        while (((not allow_unlabeled) and (y_size == 0)) or (y_size > n_classes)):
            y_size = generator.poisson(n_labels)
        y = set()
        while (len(y) != y_size):
            c = np.searchsorted(cumulative_p_c, generator.rand((y_size - len(y))))
            y.update(c)
        y = list(y)
        n_words = 0
        while (n_words == 0):
            n_words = generator.poisson(length)
        if (len(y) == 0):
            words = generator.randint(n_features, size=n_words)
            return (words, y)
        cumulative_p_w_sample = p_w_c.take(y, axis=1).sum(axis=1).cumsum()
        cumulative_p_w_sample /= cumulative_p_w_sample[(-1)]
        words = np.searchsorted(cumulative_p_w_sample, generator.rand(n_words))
        return (words, y)
    X_indices = array.array('i')
    X_indptr = array.array('i', [0])
    Y = []
    for i in range(n_samples):
        (words, y) = sample_example()
        X_indices.extend(words)
        X_indptr.append(len(X_indices))
        Y.append(y)
    X_data = np.ones(len(X_indices), dtype=np.float64)
    X = sp.csr_matrix((X_data, X_indices, X_indptr), shape=(n_samples, n_features))
    X.sum_duplicates()
    if (not sparse):
        X = X.toarray()
    if (return_indicator in (True, 'sparse', 'dense')):
        lb = MultiLabelBinarizer(sparse_output=(return_indicator == 'sparse'))
        Y = lb.fit([range(n_classes)]).transform(Y)
    elif (return_indicator is not False):
        raise ValueError("return_indicator    must    be    either    'sparse',    'dense'    or    False.")
    if return_distributions:
        return (X, Y, p_c, p_w_c)
    return (X, Y)