
    KdW                     @    d Z ddlZddlmZ ddlmZmZ 	 d	dZd	dZ	dS )
zwUtilities to get the response values of a classifier or a regressor.

It allows to make uniform checks and validation.
    N   is_classifier   )_check_response_methodcheck_is_fittedc                    ddl m}  ||           rt          | |          }| j        }t	          |          dk    rdnd}|+||                                vrt          d| d|           ||dk    r||n|d	         } ||          }|j        d
k    rn|dk    rg|j        d         dk    rV|j        d         dk    r+t          j
        ||k              d         }	|dd|	f         }n}d|j         d}
t          |
          nb|j        dk    r|dk    r||d         k    r|d	z  }n?|dk    r"t          | j        j         d| d| d          |                     |          d}}||fS )a  Compute the response values of a classifier or a regressor.

    The response values are predictions, one scalar value for each sample in X
    that depends on the specific choice of `response_method`.

    If `estimator` is a binary classifier, also return the label for the
    effective positive class.

    .. versionadded:: 1.3

    Parameters
    ----------
    estimator : estimator instance
        Fitted classifier or regressor or a fitted :class:`~sklearn.pipeline.Pipeline`
        in which the last estimator is a classifier or a regressor.

    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Input values.

    response_method : {"predict_proba", "decision_function", "predict"} or             list of such str
        Specifies the response method to use get prediction from an estimator
        (i.e. :term:`predict_proba`, :term:`decision_function` or
        :term:`predict`). Possible choices are:

        - if `str`, it corresponds to the name to the method to return;
        - if a list of `str`, it provides the method names in order of
          preference. The method returned corresponds to the first method in
          the list and which is implemented by `estimator`.

    pos_label : int, float, bool or str, default=None
        The class considered as the positive class when computing
        the metrics. By default, `estimators.classes_[1]` is
        considered as the positive class.

    Returns
    -------
    y_pred : ndarray of shape (n_samples,)
        Target scores calculated from the provided response_method
        and `pos_label`.

    pos_label : int, float, bool, str or None
        The class considered as the positive class when computing
        the metrics. Returns `None` if `estimator` is a regressor.

    Raises
    ------
    ValueError
        If `pos_label` is not a valid label.
        If the shape of `y_pred` is not consistent for binary classifier.
        If the response method can be applied to a classifier only and
        `estimator` is a regressor.
    r   r   r   binary
multiclassNz
pos_label=z+ is not a valid label: It should be one of predict_probar   zGot predict_proba of shape z', but need classifier with two classes.decision_functionpredictz? should either be a classifier to be used with response_method=zR or the response_method should be 'predict'. Got a regressor with response_method=	 instead.)sklearn.baser   r   classes_lentolist
ValueError__name__shapenpflatnonzero	__class__r   )	estimatorXresponse_method	pos_labelr   prediction_methodclassestarget_typey_predcol_idxerr_msgs              7lib/python3.11/site-packages/sklearn/utils/_response.py_get_response_valuesr&      s   v +*****}Y %729oNN$"%g,,!"3"3hh Ygnn6F6F%F%F$Y $ $!$ $   ;(#:#:%.%:		I""1%%%88h&&6<?a+?+?<?a'' nW	-ABB1EG#AAAwJ/FF7fl 7 7 7  %W---'+>>>h&&
**bLFi''&/ . .-<. . #. . .   &--a00$	9    c                 <   d}t          |            t          |           s t          |d| j        j         dz             t          | j                  dk    r(t          |dt          | j                   dz             |dk    rddg}t          | |||	          S )
a  Compute the response values of a binary classifier.

    Parameters
    ----------
    estimator : estimator instance
        Fitted classifier or a fitted :class:`~sklearn.pipeline.Pipeline`
        in which the last estimator is a binary classifier.

    X : {array-like, sparse matrix} of shape (n_samples, n_features)
        Input values.

    response_method : {'auto', 'predict_proba', 'decision_function'}
        Specifies whether to use :term:`predict_proba` or
        :term:`decision_function` as the target response. If set to 'auto',
        :term:`predict_proba` is tried first and if it does not exist
        :term:`decision_function` is tried next.

    pos_label : int, float, bool or str, default=None
        The class considered as the positive class when computing
        the metrics. By default, `estimators.classes_[1]` is
        considered as the positive class.

    Returns
    -------
    y_pred : ndarray of shape (n_samples,)
        Target scores calculated from the provided response_method
        and pos_label.

    pos_label : int, float, bool or str
        The class considered as the positive class when computing
        the metrics.
    z/Expected 'estimator' to be a binary classifier.z Got r   r   z classes instead.autor   r   )r   )r   r   r   r   r   r   r   r&   )r   r   r   r   classification_errors        r%   _get_response_values_binaryr+   r   s    B MI## 
 #R9+>+G#R#R#RR
 
 	
 
Y	 	 A	%	% #U3y/A+B+B#U#U#UU
 
 	
 &  *,?@		   r'   )N)
__doc__numpyr   baser   
validationr   r   r&   r+    r'   r%   <module>r1      s                     ? ? ? ? ? ? ? ? 	d d d dN5 5 5 5 5 5r'   