o
    i>7                     @   s  d dl Z d dlZd dlZd dlmZmZmZmZ d dl	m
Z
 d dlmZmZ d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZmZ d d
lmZmZ edd\ZZeeddZedd edd ZZ ej!"dg ddd Z#ej!"dddgdd Z$ej!"dddddggej!"dddgdd Z%ej!"dg ddd Z&ej!"dddgd d! Z'ej!"dddgd"d# Z(ej!"dddgej!"dddgd$d% Z)ej!"d&e ee d'dd(ife ee d)d(d*d+fe eed,ddifgd-d. Z*ej!"dddgd/d0 Z+ej!"dddgd1d2 Z,ej!"d3ed4d d5dfed4d d5dfe dfgd6d7 Z-d8d9 Z.ej!"dg d:d;d< Z/d=d> Z0dS )?    N)	load_irismake_classificationmake_multilabel_classificationmake_regression)IsolationForest)LinearRegressionLogisticRegression)ClassifierChain)scale)DecisionTreeClassifierDecisionTreeRegressor)_MockEstimatorOnOffPrediction)_get_response_values_get_response_values_binary)assert_allcloseassert_array_equalT)Z
return_X_yF)copyd   response_method)decision_functionpredict_probapredict_log_probac                 C   s`   t | gd}d}|jj d}tjt|d t||| d W d   dS 1 s)w   Y  dS )zLCheck the error message with regressor an not supported response
    method.)Zresponse_methods)Zmocking_dataZmocking_targetz should either be a classifiermatchr   N)r   	__class____name__pytestraises
ValueErrorr   )r   Zmy_estimatorXerr_msg r"   p/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/sklearn/utils/tests/test_response.py(test_get_response_values_regressor_error   s   "r$   return_response_method_usedc                 C   sn   t ddd\}}t ||}t||d| d}t|d || |d du s)J | r3|d dks5J dS dS )	z=Check the behaviour of `_get_response_values` with regressor.
   r   	n_samplesrandom_statepredictr   r%      N   )r   r   fitr   r   r*   )r%   r    yZ	regressorresultsr"   r"   r#   "test_get_response_values_regressor+   s   r1   r*   r   c                 C   s   t ddd\}}tdd||}t||| |d}t| tr"| d n| }t||}t|d || |d du s:J |rD|d |ksFJ dS dS )	zDCheck the behaviour of `_get_response_values` with outlier detector.2   r   r'   r)   r+   r,   Nr-   )r   r   r.   r   
isinstancelistgetattrr   )r   r%   r    r/   Zoutlier_detectorr0   Zchosen_response_methodZprediction_methodr"   r"   r#   *test_get_response_values_outlier_detection<   s"   	
r7   )r   r   r*   r   c                 C   sh   t dddd\}}t ||}d}tjt|d t||| dd W d	   d	S 1 s-w   Y  d	S )
zVCheck that `_get_response_values` raises the proper error message with
    classifier.r&   r-   r   r(   	n_classesr)   zDpos_label=whatever is not a valid label: It should be one of \[0 1\]r   Zwhateverr   	pos_labelN)r   r   r.   r   r   r   r   )r   r    r/   
classifierr!   r"   r"   r#   5test_get_response_values_classifier_unknown_pos_labelW   s   "r=   r   r   c                 C   sp   t dddd\}}t|}t ||}d}tjt|d t||| d W d   dS 1 s1w   Y  dS )	zpCheck that `_get_response_values` will raise an error when `y_pred` has a
    single class with `predict_proba`.r&   r-   r   r8   zJGot predict_proba of shape \(10, 1\), but need classifier with two classesr   r   N)	r   npZ
zeros_liker   r.   r   r   r   r   )r   r    Zy_two_classZy_single_classr<   r!   r"   r"   r#   Htest_get_response_values_classifier_inconsistent_y_pred_for_binary_probal   s   
"r?   c                 C   s   t ddddgdd\}}t ||}d}t|||d| d	}t|d || |d
 d
ks0J | r:|d dks:J t||||jd | d	}t|d ||d  |d
 dksZJ | rd|d dksfJ dS dS )zaCheck the behaviour of `_get_response_values` with `decision_function`
    and binary classifier.r&   r-   333333?ffffff?r   r(   r9   weightsr)   r   Nr   r;   r%   r,   )r   r   r.   r   r   r   classes_)r%   r    r/   r<   r   r0   r"   r"   r#   <test_get_response_values_binary_classifier_decision_function~   s@   
rG   c           	      C   s   t ddddgdd\}}t ||}t|||d| d}t|d t|||ddd	f  |d	 d	ks6J | rIt|d
ks@J |d |ksHJ nt|dksQJ t||||jd | d^}}}t|t|||dddf  |dksvJ dS )zQCheck that `_get_response_values` with `predict_proba` and binary
    classifier.r&   r-   r@   rA   r   rB   NrD   r,      )r   r   r.   r   r   r6   lenrF   )	r%   r   r    r/   r<   r0   y_predr;   _r"   r"   r#   8test_get_response_values_binary_classifier_predict_proba   s:   
$ rL   z estimator, X, y, err_msg, paramsz.Expected 'estimator' to be a binary classifierautozCpos_label=unknown is not a valid label: It should be one of \[0 1\]unknownr:   z.be a binary classifier. Got 3 classes instead.c                 C   sR   |  || tjt|d t| |fi | W d   dS 1 s"w   Y  dS )zMCheck that we raise the proper error messages in _get_response_values_binary.r   N)r.   r   r   r   r   )	estimatorr    r/   r!   paramsr"   r"   r#   test_get_response_error   s   "rQ   c                 C   s   t  tt}t|td| d}t|d |tdddf  |d dks'J | r1|d dks1J t|tdd| d}t|d |tdddf  |d dksRJ | r\|d dks^J dS dS )zKCheck the behaviour of `_get_response_values_binary` using `predict_proba`.r   r+   r   Nr,   r-   rD   )r   r.   X_binaryy_binaryr   r   r   r%   r<   r0   r"   r"   r#   test_get_response_predict_proba   s0     rU   c                 C   s   t  tt}t|td| d}t|d |t |d dks!J | r+|d dks+J t|tdd| d}t|d |td  |d dksHJ | rR|d dksTJ dS dS )	zMCheck the behaviour of `_get_response_values_binary` using decision_function.r   r+   r   r,   r-   rD   rE   N)r   r.   rR   rS   r   r   r   rT   r"   r"   r#   #test_get_response_decision_function  s0   rV   zestimator, response_methodr-   )	max_depthr)   c                 C   s   |  tt t| t|d\}}|du sJ |jtjd t| jfks$J |dkr8t|dk|dk	 s6J dS |dkrD|dk	 sFJ dS dS )zCheck that we can call `_get_response_values` with a multiclass estimator.
    It should return the predictions untouched.
    r   Nr   r   r,   r   g        )
r.   r    r/   r   shaperI   rF   r>   logical_andall)rO   r   Zpredictionsr;   r"   r"   r#   #test_get_response_values_multiclass-  s   
 r[   c                  C   s   t  tt} t| tddgdd\}}}t|| tdddf  |dks(J |dks.J t| tddgdd\}}}t|| t |dksIJ |dksOJ dS )zMCheck the behaviour of passing a list of responses to `_get_response_values`.r   r   Tr+   Nr,   )r   r.   rR   rS   r   r   r   r   )r<   rJ   r;   r   r"   r"   r#   +test_get_response_values_with_response_listF  s&   r\   )r   r   r*   c                 C   s   t dd\}}tt ||}t||| d\}}|d u sJ |j|jks'J | dkr;t|dk|dk s9J d S | dkrU|dk 	 dksIJ |dk	 dksSJ d S t
|dk|dk scJ d S )Nr   r3   r   r   r,   r   )r   r	   r   r.   r   rX   r>   rY   rZ   sum
logical_or)r   r    YrO   rJ   r;   r"   r"   r#   -test_get_response_values_multilabel_indicatora  s   
  r`   c                  C   s|   t jddd} t t dd}t | |}t	  t
dt t|| dd W d	   d	S 1 s7w   Y  d	S )
a  
    Ensure `_get_response_values` doesn't raise spurious warning.

    "The number of unique classes is greater than > 50% of samples"
    warning should not be raised when calling `type_of_target(classes_)`.

    Non-regression test for issue #31583.
    r   x   rH         errorr   r   N)r>   randomZRandomStateZrandnrepeatZaranger   r.   warningscatch_warningssimplefilterUserWarningr   )r    r/   Zclfr"   r"   r#   9test_response_values_type_of_target_on_classes_no_warningx  s   	
"rk   )1rg   numpyr>   r   Zsklearn.datasetsr   r   r   r   Zsklearn.ensembler   Zsklearn.linear_modelr   r   Zsklearn.multioutputr	   Zsklearn.preprocessingr
   Zsklearn.treer   r   Zsklearn.utils._mockingr   Zsklearn.utils._responser   r   Zsklearn.utils._testingr   r   r    r/   rR   rS   markZparametrizer$   r1   r7   r=   r?   rG   rL   rQ   rU   rV   r[   r\   r`   rk   r"   r"   r"   r#   <module>   s    





))




