Repository: scikit-learn/scikit-learn
File: sklearn/inspection/_plot/decision_boundary.py (Python)

Code before:
    if response_method == "auto":
        if is_regressor(estimator):
            prediction_method = "predict"
        else:
            prediction_method = ["decision_function", "predict_proba", "predict"]
    else:
        prediction_method = response_method

    return prediction_method


class DecisionBoundaryDisplay:
    """Decisions boundary visualization.

    It is recommended to use
    :func:`~sklearn.inspection.DecisionBoundaryDisplay.from_estimator`
    to create a :class:`DecisionBoundaryDisplay`. All parameters are stored as
    attributes.

    Read more in the :ref:`User Guide <visualizations>`.

    For a detailed example comparing the decision boundaries of multinomial and
    one-vs-rest logistic regression, please see
    :ref:`sphx_glr_auto_examples_linear_model_plot_logistic_multinomial.py`.

    .. versionadded:: 1.1

    Parameters
    ----------
    xx0 : ndarray of shape (grid_resolution, grid_resolution)
        First output of :func:`meshgrid <numpy.meshgrid>`.

    xx1 : ndarray of shape (grid_resolution, grid_resolution)
        Second output of :func:`meshgrid <numpy.meshgrid>`.

    n_classes : int
        Expected number of unique classes or labels if `response` was generated by a
        :term:`classifier` or a :term:`clusterer`.

        For :term:`outlier detectors`, `n_classes` should be set to 2 by definition
        (inlier or outlier).

        For :term:`regressors`, `n_classes` should also be set to 2 by convention
        (continuous responses are displayed the same way as unthresholded binary
        responses).

        .. versionadded:: 1.9

    response : ndarray of shape (grid_resolution, grid_resolution) or \
            (grid_resolution, grid_resolution, n_classes)
        Values of the response function.

Review comment (suggestion):
Could we add a reference to mpl `is_color_like` function, just to help anyone reading the code.

Code after:
    if response_method == "auto":
        if is_regressor(estimator):
            prediction_method = "predict"
        else:
            prediction_method = ["decision_function", "predict_proba", "predict"]
    else:
        prediction_method = response_method

    return prediction_method


def _select_colors(mpl, multiclass_colors, n_classes):
    """Select colors for multiclass decision boundary display.

    Parameters
    ----------
    mpl : module
        Imported `matplotlib` module.

    multiclass_colors : list of color-like, str, or None
        Color specification for multiclass plots.

        - If `None`, defaults to `"tab10"` when `n_classes <= 10`, otherwise
          `"gist_rainbow"`.
        - If `str`, interpreted as a Matplotlib colormap name.
        - If `list`, each entry must be a valid Matplotlib color-like value.

    n_classes : int
        Number of colors to select.

    Returns
    -------
    colors : list or ndarray of shape (n_classes, 4)
        RGBA colors, one per class.

    """

    if multiclass_colors is None:
        multiclass_colors = "tab10" if n_classes <= 10 else "gist_rainbow"

    if isinstance(multiclass_colors, str):
        if multiclass_colors not in mpl.pyplot.colormaps():
            raise ValueError(
                "When 'multiclass_colors' is a string, it must be a valid "
                f"Matplotlib colormap. Got: {multiclass_colors}"
            )
        cmap = mpl.pyplot.get_cmap(multiclass_colors)
        if cmap.N < n_classes:
            raise ValueError(
                f"Colormap '{multiclass_colors}' only has {cmap.N} colors, but "
                f"{n_classes} classes are to be displayed. Please specify a "