ó
    Ñ]ju/  ã                   ó^   • S r SSKrSSKJr  SSKJr  SSKJrJ	r	  S r
S r  S
S jr S
S	 jrg)zwUtilities to get the response values of a classifier or a regressor.

It allows to make uniform checks and validation.
é    N)Úis_classifier)Útype_of_target)Ú_check_response_methodÚcheck_is_fittedc                 óp  • US:X  a,  U R                   S   S:  a  [        SU R                    S35      eUS:X  a$  [        R                  " X#:H  5      S   nU SS2U4   $ US:X  aN  [	        U [
        5      (       a7  [        R                  " U  Vs/ s H  oUSS2S	4   PM     sn5      R                  $ U $ U $ s  snf )
a_  Get the response values when the response method is `predict_proba`.

This function process the `y_pred` array in the binary and multi-label cases.
In the binary case, it selects the column corresponding to the positive
class. In the multi-label case, it stacks the predictions if they are not
in the "compressed" format `(n_samples, n_outputs)`.

Parameters
----------
y_pred : ndarray
    Output of `estimator.predict_proba`. The shape depends on the target type:

    - for binary classification, it is a 2d array of shape `(n_samples, 2)`;
    - for multiclass classification, it is a 2d array of shape
      `(n_samples, n_classes)`;
    - for multilabel classification, it is either a list of 2d arrays of shape
      `(n_samples, 2)` (e.g. `RandomForestClassifier` or `KNeighborsClassifier`) or
      an array of shape `(n_samples, n_outputs)` (e.g. `MLPClassifier` or
      `RidgeClassifier`).

target_type : {"binary", "multiclass", "multilabel-indicator"}
    Type of the target.

classes : ndarray of shape (n_classes,) or list of such arrays
    Class labels as reported by `estimator.classes_`.

pos_label : int, float, bool or str
    Only used with binary and multiclass targets.

Returns
-------
y_pred : ndarray of shape (n_samples,), (n_samples, n_classes) or             (n_samples, n_output)
    Compressed predictions format as requested by the metrics.
Úbinaryé   é   zGot predict_proba of shape z', but need classifier with two classes.r   Nzmultilabel-indicatoréÿÿÿÿ)ÚshapeÚ
ValueErrorÚnpÚflatnonzeroÚ
isinstanceÚlistÚvstackÚT)Úy_predÚtarget_typeÚclassesÚ	pos_labelÚcol_idxÚps         ÚT/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sklearn/utils/_response.pyÚ_process_predict_probar      sÀ   € ðH �hÓ 6§<¡<°¡?°QÓ#6äØ)¨&¯,©,¨ð 8+ð +ó
ð 	
ð
 �hÓÜ—.’. Ñ!5Ó6°qÑ9ˆØ’a˜�jÑ!Ð!Ø	Ð.Ó	.ô �fœd×#Ñ#ä—9’9±Ó7²¨1¢ 2 œh±Ñ7Ó8×:Ñ:Ð:ð ˆMà€Mùò 8s   ÂB3c                 ó,   • US:X  a  X2S   :X  a  SU -  $ U $ )a  Get the response values when the response method is `decision_function`.

This function process the `y_pred` array in the binary and multi-label cases.
In the binary case, it inverts the sign of the score if the positive label
is not `classes[1]`. In the multi-label case, it stacks the predictions if
they are not in the "compressed" format `(n_samples, n_outputs)`.

Parameters
----------
y_pred : ndarray
    Output of `estimator.decision_function`. The shape depends on the target type:

    - for binary classification, it is a 1d array of shape `(n_samples,)` where the
      sign is assuming that `classes[1]` is the positive class;
    - for multiclass classification, it is a 2d array of shape
      `(n_samples, n_classes)`;
    - for multilabel classification, it is a 2d array of shape `(n_samples,
      n_outputs)`.

target_type : {"binary", "multiclass", "multilabel-indicator"}
    Type of the target.

classes : ndarray of shape (n_classes,) or list of such arrays
    Class labels as reported by `estimator.classes_`.

pos_label : int, float, bool or str
    Only used with binary and multiclass targets.

Returns
-------
y_pred : ndarray of shape (n_samples,), (n_samples, n_classes) or             (n_samples, n_output)
    Compressed predictions format as requested by the metrics.
r   r   r   © ©r   r   r   r   s       r   Ú_process_decision_functionr   L   s%   € ðF �hÓ 9¸±
Ó#:Ø�F‰{ÐØ€Mó    c                 ód  • SSK JnJn  U" U 5      (       aŸ  [        X5      nU R                  n[        U5      n	U	S;   a5  Ub$  X8R                  5       ;  a  [        SU SU 35      eUc  U	S:X  a  US   nU" U5      n
UR                  S	;   a  [        U
U	UUS
9n
O‚UR                  S:X  a  [        U
U	UUS
9n
OeU" U 5      (       a  [        X5      nU" U5      Sp:OCUS:w  a(  [        U R                  R                   SU SU S35      eU R                  nU" U5      Sp:U(       a  X£UR                  4$ X£4$ )a'  Compute the response values of a classifier, an outlier detector, or a regressor.

The response values are predictions such that it follows the following shape:

- for binary classification, it is a 1d array of shape `(n_samples,)`;
- for multiclass classification, it is a 2d array of shape `(n_samples, n_classes)`;
- for multilabel classification, it is a 2d array of shape `(n_samples, n_outputs)`;
- for outlier detection, it is a 1d array of shape `(n_samples,)`;
- for regression, it is a 1d array of shape `(n_samples,)`.

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

This utility is used primarily in the displays and the scikit-learn scorers.

.. versionadded:: 1.3

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

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

response_method : {"predict_proba", "predict_log_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:`predict_log_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. If `None` and target is 'binary', `estimators.classes_[1]` is
    considered as the positive class.

return_response_method_used : bool, default=False
    Whether to return the response method used to compute the response
    values.

    .. versionadded:: 1.4

Returns
-------
y_pred : ndarray of shape (n_samples,), (n_samples, n_classes) or             (n_samples, n_outputs)
    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 or an outlier
    detector.

response_method_used : str
    The response method used to compute the response values. Only returned
    if `return_response_method_used` is `True`.

    .. versionadded:: 1.4

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   Úis_outlier_detector)r   Ú
multiclassNz
pos_label=z+ is not a valid label: It should be one of r   r   )Úpredict_probaÚpredict_log_probar   Ú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"   r   Úclasses_r   Útolistr   Ú__name__r   r   Ú	__class__r'   )Ú	estimatorÚXÚresponse_methodr   Úreturn_response_method_usedr   r"   Úprediction_methodr   r   r   s              r   Ú_get_response_valuesr3   t   s‚  € ÷d @á�Y×ÑÜ2°9ÓNÐØ×$Ñ$ˆÜ$ WÓ-ˆàÐ2Ó2ØÑ$¨¿.¹.Ó:JÓ)JÜ Ø   ð ,Ø%˜Yð(óð ð Ñ" {°hÓ'>Ø# B™K�	á" 1Ó%ˆà×%Ñ%Ð)OÓOÜ+ØØ'ØØ#ñ	‰Fð ×'Ñ'Ð+>Ó>Ü/ØØ'ØØ#ñ	ˆFøñ 
˜Y×	'Ñ	'Ü2°9ÓNÐÙ-¨aÓ0°$‘	à˜iÓ'ÜØ×&Ñ&×/Ñ/Ð0ð 1-Ø-<Ð,=ð >Mà"Ð# 9ð.óð ð &×-Ñ-ÐÙ-¨aÓ0°$�	æ"ØÐ"3×"<Ñ"<Ð<Ð<ØÐÐr    c                 ó2  • Sn[        U 5        [        U 5      (       d&  [        USU R                  R                   S3-   5      e[        U R                  5      S:w  a%  [        US[        U R                  5       S3-   5      eUS:X  a  SS/n[        U UUUUS	9$ )
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.

return_response_method_used : bool, default=False
    Whether to return the response method used to compute the response
    values.

    .. versionadded:: 1.5

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.

response_method_used : str
    The response method used to compute the response values. Only returned
    if `return_response_method_used` is `True`.

    .. versionadded:: 1.5
z/Expected 'estimator' to be a binary classifier.z Got r(   r
   z classes instead.Úautor$   r&   )r   r1   )r   r   r   r-   r,   Úlenr*   r3   )r.   r/   r0   r   r1   Úclassification_errors         r   Ú_get_response_values_binaryr8   ù   s»   € ð^ MÐä�IÔÜ˜×#Ñ#ÜØ  U¨9×+>Ñ+>×+GÑ+GÐ*HÈ	Ð#RÑRó
ð 	
ô 
ˆY×ÑÓ	  AÓ	%ÜØ  U¬3¨y×/AÑ/AÓ+BÐ*CÐCTÐ#UÑUó
ð 	
ð ˜&Ó Ø*Ð,?Ð@ˆäØØ	ØØØ$?ñð r    )NF)Ú__doc__Únumpyr   r)   r   Úsklearn.utils.multiclassr   Úsklearn.utils.validationr   r   r   r   r3   r8   r   r    r   Ú<module>r=      s@   ðñó å &Ý 3ß Lò9òx%ðX Ø %ôBðL PUõDr    