o
    ?Hh4                     @   s  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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)
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.)response_methods)mocking_datamocking_targetz should either be a classifiermatchr   N)r   	__class____name__pytestraises
ValueErrorr   )r   my_estimatorXerr_msg r'   a/home/air/sanwanet/gpt-api/venv/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%   y	regressorresultsr'   r'   r(   "test_get_response_values_regressor)   s   r7   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.   r0   r1   Nr2   )r   r   r3   r   
isinstancelistgetattrr   )r   r*   r%   r4   outlier_detectorr6   chosen_response_methodprediction_methodr'   r'   r(   *test_get_response_values_outlier_detection:   s"   	
r@   )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+   r2   r   r-   	n_classesr.   zDpos_label=whatever is not a valid label: It should be one of \[0 1\]r   whateverr   	pos_labelN)r   r   r3   r!   r"   r#   r   )r   r%   r4   
classifierr&   r'   r'   r(   5test_get_response_values_classifier_unknown_pos_labelU   s   "rG   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+   r2   r   rA   zJGot predict_proba of shape \(10, 1\), but need classifier with two classesr   r   N)	r   np
zeros_liker   r3   r!   r"   r#   r   )r   r%   y_two_classy_single_classrF   r&   r'   r'   r(   Htest_get_response_values_classifier_inconsistent_y_pred_for_binary_probaj   s   
"rL   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+   r2   333333?ffffff?r   r-   rB   weightsr.   r   Nr   rE   r*   r1   )r   r   r3   r   r   r   classes_)r*   r%   r4   rF   r   r6   r'   r'   r(   <test_get_response_values_binary_classifier_decision_function|   s@   
rT   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+   r2   rM   rN   r   rO   NrQ   r1      )r   r   r3   r   r   r<   lenrS   )	r*   r   r%   r4   rF   r6   y_predrE   _r'   r'   r(   8test_get_response_values_binary_classifier_predict_proba   s:   
$ rY   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\]unknownrD   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)r3   r!   r"   r#   r   )	estimatorr%   r4   r&   paramsr'   r'   r(   test_get_response_error   s   "r^   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   r0   r   Nr1   r2   rQ   )r   r3   X_binaryy_binaryr   r   r   r*   rF   r6   r'   r'   r(   test_get_response_predict_proba   s0     rb   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   r0   r   r1   r2   rQ   rR   N)r   r3   r_   r`   r   r   r   ra   r'   r'   r(   #test_get_response_decision_function  s0   rc   zestimator, response_methodr2   )	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   r1   r   g        )
r3   r%   r4   r   shaperV   rS   rH   logical_andall)r\   r   predictionsrE   r'   r'   r(   #test_get_response_values_multiclass+  s   
 ri   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   Tr0   Nr1   )r   r3   r_   r`   r   r   r   r   )rF   rW   rE   r   r'   r'   r(   +test_get_response_values_with_response_listD  s&   rj   )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   r9   r   r   r1   r   )r   r	   r   r3   r   re   rH   rf   rg   sum
logical_or)r   r%   Yr\   rW   rE   r'   r'   r(   -test_get_response_values_multilabel_indicator_  s   
  rn   )/numpyrH   r!   sklearn.datasetsr   r   r   r   sklearn.ensembler   sklearn.linear_modelr   r   sklearn.multioutputr	   sklearn.preprocessingr
   sklearn.treer   r   sklearn.utils._mockingr   sklearn.utils._responser   r   sklearn.utils._testingr   r   r%   r4   r_   r`   markparametrizer)   r7   r@   rG   rL   rT   rY   r^   rb   rc   ri   rj   rn   r'   r'   r'   r(   <module>   s    


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