Repository: scikit-learn/scikit-learn
File: sklearn/metrics/_classification.py (Python)

Code before:
    ----------
    y_true : array-like

    y_pred : array-like

    sample_weight : array-like, default=None

    Returns
    -------
    type_true : one of {'multilabel-indicator', 'multiclass', 'binary'}
        The type of the true target data, as output by
        ``utils.multiclass.type_of_target``.

    y_true : array or indicator matrix

    y_pred : array or indicator matrix

    sample_weight : array or None
    """
    xp, _ = get_namespace(y_true, y_pred, sample_weight)
    check_consistent_length(y_true, y_pred, sample_weight)
    type_true = type_of_target(y_true, input_name="y_true")
    type_pred = type_of_target(y_pred, input_name="y_pred")
    for array in [y_true, y_pred]:
        if _num_samples(array) < 1:
            raise ValueError(
                "Found empty input array while a minimum of 1 sample is required."
            )
    if sample_weight is not None:
        sample_weight = _check_sample_weight(
            sample_weight, y_true, force_float_dtype=False
        )

    y_type = {type_true, type_pred}
    if y_type == {"binary", "multiclass"}:
        y_type = {"multiclass"}

    if len(y_type) > 1:
        raise ValueError(
            "Classification metrics can't handle a mix of {0} and {1} targets".format(
                type_true, type_pred
            )
        )

    # We can't have more than one value on y_type => The set is no more needed
    y_type = y_type.pop()

    # No metrics support "multiclass-multioutput" format
    if y_type not in ["binary", "multiclass", "multilabel-indicator"]:
        raise ValueError("{0} is not supported".format(y_type))


Review comment (bug):
Putting the new raise ValueError below the `type_of_target` checks, because we need to raise the 
"legacy multi-label data representation" error from `sklearn/utils/multiclass.py` first. (test__check_targets_sparse_inputs fails otherwise)

Code after:
    as CSR sparse label indicators.

    Parameters
    ----------
    y_true : array-like

    y_pred : array-like

    sample_weight : array-like, default=None

    Returns
    -------
    type_true : one of {'multilabel-indicator', 'multiclass', 'binary'}
        The type of the true target data, as output by
        ``utils.multiclass.type_of_target``.

    y_true : array or indicator matrix

    y_pred : array or indicator matrix

    sample_weight : array or None
    """
    xp, _ = get_namespace(y_true, y_pred, sample_weight)
    check_consistent_length(y_true, y_pred, sample_weight)
    type_true = type_of_target(y_true, input_name="y_true")
    type_pred = type_of_target(y_pred, input_name="y_pred")
    for array in [y_true, y_pred]:
        if _num_samples(array) < 1:
            raise ValueError(
                "Found empty input array (e.g., `y_true` or `y_pred`) while a minimum "
                "of 1 sample is required."
            )
    if sample_weight is not None:
        sample_weight = _check_sample_weight(
            sample_weight, y_true, force_float_dtype=False
        )

    y_type = {type_true, type_pred}
    if y_type == {"binary", "multiclass"}:
        y_type = {"multiclass"}

    if len(y_type) > 1:
        raise ValueError(
            "Classification metrics can't handle a mix of {0} and {1} targets".format(
                type_true, type_pred
            )
        )

    # We can't have more than one value on y_type => The set is no more needed
    y_type = y_type.pop()