
    Wh
<                         d dl Z d dlmZ d dlZddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZmZ  G d
 d      Zd Zd Zd Zd Zd Zd Zd Zy)    N)Mapping   )check_consistent_length)check_matplotlib_support)_get_response_values_binary)parse_version)type_of_target)_check_pos_label_consistency_num_samplesc                       e Zd ZdZddddZeddddd       Zeddddd	       Zed
        Ze	d        Z
e	d        Zy)"_BinaryClassifierCurveDisplayMixinzMixin class to be used in Displays requiring a binary classifier.

    The aim of this class is to centralize some validations regarding the estimator and
    the target and gather the response of the estimator.
    N)axnamec          	          t        | j                  j                   d       dd lm} ||j                         \  }}|t        | dt        | dd             }||j                  |fS )Nz.plotr   estimator_namer   )r   	__class____name__matplotlib.pyplotpyplotsubplotsgetattrfigure)selfr   r   plt_s        Q/var/www/html/jupyter_env/lib/python3.12/site-packages/sklearn/utils/_plotting.py_validate_plot_paramsz8_BinaryClassifierCurveDisplayMixin._validate_plot_params   sc     DNN$;$;#<E!BC':LLNEAr <4!1743NOD299d""    auto)response_method	pos_labelr   c                    t        | j                   d       ||j                  j                  n|}t        ||||      \  }}|||fS )Nz.from_estimator)r    r!   )r   r   r   r   )cls	estimatorXyr    r!   r   y_preds           r   !_validate_and_get_response_valueszD_BinaryClassifierCurveDisplayMixin._validate_and_get_response_values$   sX     	!CLL>!AB/3|y""++7+	
	 y$&&r   )sample_weightr!   r   c                    t        | j                   d       t        |      dk7  rt        dt        |       d      t	        |||       t        ||      }||nd}||fS )Nz.from_predictionsbinaryz The target y is not binary. Got  type of target.
Classifier)r   r   r	   
ValueErrorr   r
   )r#   y_truer'   r)   r!   r   s         r   !_validate_from_predictions_paramszD_BinaryClassifierCurveDisplayMixin._validate_from_predictions_params5   sz     	!CLL>1B!CD&!X-2>&3I2J K  
 	 >0FC	't\$r   c                   t        | j                   d       ddh}t        fd|D              st        d| d      t	        d   d   d         t	        d   d	   d         }}t        |      ||z   k7  rt        d
||z    dt        |       d      t        |      dk7  rt        dt        |       d      t        |||       	 t        ||      }|S # t        $ r)}	t        t        |	      j                  dd            d }	~	ww xY w)Nz.from_cv_resultsr$   indicesc              3   &   K   | ]  }|v  
 y w)N ).0key
cv_resultss     r   	<genexpr>zV_BinaryClassifierCurveDisplayMixin._validate_from_cv_results_params.<locals>.<genexpr>U   s     >3*$>s   zB`cv_results` does not contain one of the following required keys: zr. Set explicitly the parameters `return_estimator=True` and `return_indices=True` to the function`cross_validate`.trainr   testz=`X` does not contain the correct number of samples. Expected z, got .r+   z"The target `y` is not binary. Got r,   r/   r&   )r   r   allr.   lenr   r	   r   r
   strreplace)
r#   r7   r%   r&   r)   r!   required_keys
train_size	test_sizees
    `        r    _validate_from_cv_results_paramszC_BinaryClassifierCurveDisplayMixin._validate_from_cv_results_paramsH   sL    	!CLL>1A!BC$i0>>>T / "$$  
9%g.q12
9%f-a01 

 ?j944&236,q/9J!M 
 !(4^A5F4GGWX  	 1m4	<4YBI
 	  	<SV^^Hc:;;	<s   C 	D#$DDc                 R    | || d| d| dd}|S | 
| d| d}|S ||}|S d}|S )z;Helper to get legend label using `name` and `legend_metric`Nz (z = 0.2f)r4   )curve_legend_metric
curve_namelegend_metric_namelabels       r   _get_legend_labelz4_BinaryClassifierCurveDisplayMixin._get_legend_labelv   sz     *z/E!l"%7$8<OPT;UUVWE  !,)*#.A$-GHE
 	 #E  Er   c           	         |r|rt        d      |rt        j                  dt               |}t	        |t
              r t        |      | k7  rt        d|  d| d      t	        |t
              r-t        |      dk7  rt	        |t
              st        d|  d      t	        |t              r|g}t	        |t
              rt        |      dk(  r|| z  }|d	g| z  n|}t	        |t              r|g| z  }d
ddd}|| dkD  r|g| z  }ni g}g }d|v rat        j                  |d   |d   |      }|d   "|d   |d	d d|d   ddz   }n|d|d   dz   }|j                  |gd	g| dz
  z  z          n=t        |d   |      D ]+  \  }	}
|j                  t        j                  |	|
|             - t        |      D cg c]  \  }}t        d|i||          }}}|S c c}}w )a  Get validated line kwargs for each curve.

        Parameters
        ----------
        n_curves : int
            Number of curves.

        name : list of str or None
            Name for labeling legend entries.

        legend_metric : dict
            Dictionary with "mean" and "std" keys, or "metric" key of metric
            values for each curve. If None, "label" will not contain metric values.

        legend_metric_name : str
            Name of the summary value provided in `legend_metrics`.

        curve_kwargs : dict or list of dict or None
            Dictionary with keywords passed to the matplotlib's `plot` function
            to draw the individual curves. If a list is provided, the
            parameters are applied to the curves sequentially. If a single
            dictionary is provided, the same parameters are applied to all
            curves.

        **kwargs : dict
            Deprecated. Keyword arguments to be passed to matplotlib's `plot`.
        zCannot provide both `curve_kwargs` and `kwargs`. `**kwargs` is deprecated in 1.7 and will be removed in 1.9. Pass all matplotlib arguments to `curve_kwargs` as a dictionary.z}`**kwargs` is deprecated and will be removed in 1.9. Pass all matplotlib arguments to `curve_kwargs` as a dictionary instead.z>`curve_kwargs` must be None, a dictionary or a list of length z. Got: r;   r   zfTo avoid labeling individual curves that have the same appearance, `curve_kwargs` should be a list of z dictionaries. Alternatively, set `name` to `None` or a single string to label a single legend entry with mean ROC AUC score of all curves.Ng      ?z--blue)alpha	linestylecolormeanr   stdz +/- rF   rG   metricrK   )r.   warningswarnFutureWarning
isinstancelistr=   r>   r   r   rL   extendzipappend	enumerate_validate_style_kwargs)n_curvesr   legend_metricrJ   curve_kwargskwargsdefault_multi_curve_kwargslabelslabel_aggregaterH   rI   fold_idxrK   curve_kwargs_s                 r   _validate_curve_kwargsz9_BinaryClassifierCurveDisplayMixin._validate_curve_kwargs   sw   J F? 
 MMR
 "LlD)c,.?8.KP*GL>4  tT"D	Q|T266>Z @OO  dC 6DdD!c$i1n(?D$(Lv d lG,(>H4L/2PV%W"!| :;hF "t]"@RRf%tAw0BO
 U#/7&',}U7KD6QQR/SS $
 (E-2Ft1L*MM $ MM?+tf1.EEF36}X7NPT3U /#Z6HH+Z9K $-V#4
% #GU#3\(5KL
 
 	
s   :G)r   
__module____qualname____doc__r   classmethodr(   r0   rD   staticmethodrL   ri   r4   r   r   r   r      s     +/T # 174d' '  .2d $ + +Z 
 
 v vr   r   c                     | | S ||rdS dS t        |      r|j                  n|} |r| j                  d      r| dd } nd|  } n| j                  d      rd| dd  } | j                  dd      } | j	                         S )	a  Validate the `score_name` parameter.

    If `score_name` is provided, we just return it as-is.
    If `score_name` is `None`, we use `Score` if `negate_score` is `False` and
    `Negative score` otherwise.
    If `score_name` is a string or a callable, we infer the name. We replace `_` by
    spaces and capitalize the first letter. We remove `neg_` and replace it by
    `"Negative"` if `negate_score` is `False` or just remove it otherwise.
    NzNegative scoreScoreneg_   z	Negative r    )callabler   
startswithr?   
capitalize)
score_namescoringnegate_scores      r   _validate_score_namerz      s     	#/<W<)1'):W%%
$$V,'^
(5
""6*$Z^$45J''S1
$$&&r   c                     t        j                  t        j                  |             }|j                         |j	                         z  S )a   Compute the ratio between the largest and smallest inter-point distances.

    A value larger than 5 typically indicates that the parameter range would
    better be displayed with a log scale while a linear scale would be more
    suitable otherwise.
    )npdiffsortmaxmin)datar}   s     r   _interval_max_min_ratior     s1     772774=!D88:
""r   c                 b   i ddddddddd	d
dddddddddddddddddddddd d!d"d#d$d%d&d'd(d)}|j                         D ]   \  }}||v s||v st        d*| d+| d,       | j                         }|j                         D ]  }||v r||   |||   <   ||   ||<    |S )-a  Create valid style kwargs by avoiding Matplotlib alias errors.

    Matplotlib raises an error when, for example, 'color' and 'c', or 'linestyle' and
    'ls', are specified together. To avoid this, we automatically keep only the one
    specified by the user and raise an error if the user specifies both.

    Parameters
    ----------
    default_style_kwargs : dict
        The Matplotlib style kwargs used by default in the scikit-learn display.
    user_style_kwargs : dict
        The user-defined Matplotlib style kwargs.

    Returns
    -------
    valid_style_kwargs : dict
        The validated style kwargs taking into account both default and user-defined
        Matplotlib style kwargs.
    lsrP   crQ   ec	edgecolorfc	facecolorlw	linewidthmecmarkeredgecolormfcaltmarkerfacecoloraltms
markersizemewmarkeredgewidthmfcmarkerfacecoloraaantialiasedds	drawstylefontfontpropertiesfamily
fontfamilyr   fontnamesizefontsizestretchfontstretch	fontstylefontvariant
fontweighthorizontalalignmentverticalalignmentmultialignment)stylevariantweighthavamaz	Got both  and z", which are aliases of one another)items	TypeErrorcopykeys)default_style_kwargsuser_style_kwargsinvalid_to_valid_kwinvalid_key	valid_keyvalid_style_kwargsr6   s          r   r_   r_   #  s   *kW 	k 	k	
 	k 	  	& 	l 	  	  	m 	k 	  	, 	
  	
!" 	=#$  #!/2 #6";";"= Y++	=N0NK=i[ 9   .224 %%' =%%;LS;Q2378&7&<s#	= r   c                     dD ]   }| j                   |   j                  d       " dD ]!  }| j                   |   j                  dd       # y)zRemove the top and right spines of the plot.

    Parameters
    ----------
    ax : matplotlib.axes.Axes
        The axes of the plot to despine.
    )toprightF)bottomleftr   r   N)spinesset_visible
set_bounds)r   ss     r   _despiner   b  sP      (
		!  '( &
		!1%&r   c                     t        |      }|j                   d|j                  dz    }| dk7  r7|rt        d| d| d      t	        j
                  d| d| dt               | S |S )	z/Deprecate `estimator_name` in favour of `name`.r;      
deprecatedzSCannot provide both `estimator_name` and `name`. `estimator_name` is deprecated in z and will be removed in z. Use `name` only.z"`estimator_name` is deprecated in z. Use `name` instead.)r   majorminorr.   rV   rW   rX   )r   r   versionversion_removes       r   _deprecate_estimator_namer   p  s    G$Ga(9':;N%$$+9,D^DT U## 
 	0	9Q35	

 Kr   c                 2    | yt        | t              r| S | gS )z3Convert parameters to a list, leaving `None` as is.N)rY   rZ   )params    r   _convert_to_list_leaving_noner     s     }%7Nr   c           	         i }|j                         D ]  \  }}t        |t              s|||<    i | |}t        |j	                         D ch c]  }t        |       c}      dkD  r|j                         D cg c]  }| }}dj                  dj                  |dd       |d   g      }	d}
d|v rd}
dj                  d	 |j                         D              }t        |	 d
| d|
 d|       yc c}w c c}w )z>Check required and optional parameters are of the same length.r   r   z, NrT    z'name' (or self.name)z (or `plot`)c              3   B   K   | ]  \  }}| d t        |         yw)z: N)r=   )r5   r6   values      r   r8   z'_check_param_lengths.<locals>.<genexpr>  s(      &
'1sEse2c%j\"&
s   z from `z` initializationz/, should all be lists of the same length. Got: )r   rY   rZ   r=   valuesr   joinr.   )requiredoptional
class_nameoptional_providedr   r   
all_paramsr6   
param_keysparams_formattedor_plotlengths_formatteds               r   _check_param_lengthsr     s(   ~~' ,eeT"&+d#, 3H2 12J
J$5$5$785CJ89A=%/__%67cc7
7 #<<:cr?)CZPR^(TU"j0$G II &
5?5E5E5G&
 
  
|3CG9 M<<M;NP
 	
 >87s   C4<	C9)rV   collections.abcr   numpyr|   r   r   _optional_dependenciesr   	_responser   fixesr   
multiclassr	   
validationr
   r   r   rz   r   r_   r   r   r   r   r4   r   r   <module>r      sS     #  % < 2   & Bj jZ'6#<~&(
r   