a
    ht                    @   s
  d Z ddlZddlZddlZddl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ZddlZddlmZmZmZ dd	lmZ dd
lmZmZmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$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/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@ ddlAmBZB ddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKmLZLmMZMmNZNmOZOmPZP ddlQmRZRmSZS ddlTmUZU ddlVmWZW ddlXmYZYmZZZm[Z[ ddl\m]Z]m^Z^ ddl_m`Z`maZambZbmcZc ddldmeZemfZf dd lgmhZhmiZimjZj dd!lkmlZlmmZm dd"lnmoZo dd#lpmqZqmrZr dd$lsmtZtmuZumvZvmwZwmxZxmyZymzZzm{Z{ dd%l|m}Z} dd&l~mZ G d'd( d(eeZG d)d* d*efZed+d+gd,d+gd-d-gd.d-ggZeg d/Zd0d1 Zejd2eKe	eLd3d4gejd5ded6fd7dgidged8fd7died9fgd:d; Zd<d= Zd>d? Zd@dA ZejdBeDeMgdCdD ZdEdF ZdGdH ZdIdJ ZdKdL ZdMdN ZdOdP ZdQdR ZdSdT ZdUdV ZdWdX ZejdYe}dZd[ ZejdYe}d\d] Zd^d_ Zd`da ZG dbdc dceZejdddedf Zdgdh Zdidj Zejdkd+d.gejdleMeDgdmdn Zdodp Zdqdr Zdsdt Zdudv Zdwdx Zdydz Zd{d| Zd}d~ Zdd Zd'ddZdd Zdd ZejdeDddd-d3giifeMdd-d3gid.dfgdd Zdd Zdd Zdd Zdd ZejdleMel ddd3gideDel ddd3gidgdd ZejdleMe[ddddd3giddeDe[ddddd3giddgdd Zdd Zdd Zejddd Zdd Zdd Zdd Zdd Zdd ZG dd deZdd Zdd Zdd Zdd Zdd Zdd ZddĄ ZddƄ ZddȄ Zddʄ Zdd̄ Zdd΄ ZejdddgejdeDddg dѢiifeMdg dѢiddfgddԄ Zddք Zdd؄ Zddڄ Zdd܄ Zddބ Zdd Zdd Zejdddgdd Zdd Zdd ZejdeDdddgifeMded-difgdd ZejdeDdddgifeMdeddifgdd ZejdejdBeDeMgejdeuetgdd Zejdddgdd ZejdeDdfeMdfeGdfgdd Zdd Zdd  ZejdBeDeMgdd ZejdeDdfeMdfgedddd ZejdeDdfeMdfeGdfgdd Zސdd	 Zߐd
d Zdd Zejdeo ejdBeDeMgdd Ze` Zea Zejjed.dedZded< ded-< ejdejd7d-id7d.igdejed-d.gfgddejd-ddd.dҐdd7digdejeg dfdejjeg dg ddfgddejd7d-gd.gdggid7d-gd.ggigdejjd-gd.gdggd-gd.gggedfgd dejd7did7digdefgd!dejd7eid7eigdejjeegedfgd"dgd#d$ Zd%d& ZdS ((  zTest the search module    N)IterableSized)partial)StringIO)chainproduct)GeneratorType)	bernoulliexponuniform)config_context)BaseEstimatorClassifierMixinis_classifier)KMeans)ColumnTransformer)
make_blobsmake_classificationmake_multilabel_classification)LinearDiscriminantAnalysis)DummyClassifier)HistGradientBoostingClassifier)FitFailedWarning)enable_halving_search_cv)TfidfVectorizer)SimpleImputer)LinearRegressionLogisticRegressionRidgeSGDClassifier)accuracy_scoreconfusion_matrixf1_scoremake_scorerr2_scorerecall_scoreroc_auc_score)euclidean_distances)GridSearchCV
GroupKFoldGroupShuffleSplitHalvingGridSearchCVKFoldLeaveOneGroupOutLeavePGroupsOutParameterGridParameterSamplerRandomizedSearchCVStratifiedKFoldStratifiedShuffleSplittrain_test_split)BaseSearchCV"_yield_masked_array_for_each_param)OneTimeSplitter)ComplementNB)KernelDensityKNeighborsClassifierLocalOutlierFactor)Pipelinemake_pipeline)OneHotEncoderOrdinalEncoderSplineTransformerStandardScaler)SVC	LinearSVC)ConsumingScorer	_Registrycheck_recorded_metadata)DecisionTreeClassifierDecisionTreeRegressor))yield_namespace_device_dtype_combinations)CheckingClassifierMockDataFrame)MinimalClassifierMinimalRegressorMinimalTransformer_array_api_for_testsassert_allcloseassert_almost_equalassert_array_almost_equalassert_array_equal)CSR_CONTAINERS)_num_samplesc                   @   sb   e Zd ZdZdddZdd Zdd Zd	d
 Zdd ZeZ	eZ
eZdddZdddZdd ZdS )MockClassifierz8Dummy classifier to test the parameter search algorithmsr   c                 C   s
   || _ d S N	foo_param)selfrY    r[   e/var/www/html/assistant/venv/lib/python3.9/site-packages/sklearn/model_selection/tests/test_search.py__init__j   s    zMockClassifier.__init__c                 C   s$   t |t |ksJ t|| _| S rW   )lennpuniqueclasses_rZ   XYr[   r[   r\   fitm   s    zMockClassifier.fitc                 C   s
   |j d S Nr   shape)rZ   Tr[   r[   r\   predictr   s    zMockClassifier.predictc                 C   s
   || j  S rW   rX   rZ   rc   r[   r[   r\   	transformu   s    zMockClassifier.transformc                 C   s
   || j  S rW   rX   rk   r[   r[   r\   inverse_transformx   s    z MockClassifier.inverse_transformNc                 C   s   | j dkrd}nd}|S )N         ?        rX   )rZ   rc   rd   scorer[   r[   r\   rq      s    
zMockClassifier.scoreFc                 C   s
   d| j iS NrY   rX   )rZ   deepr[   r[   r\   
get_params   s    zMockClassifier.get_paramsc                 K   s   |d | _ | S rr   rX   )rZ   paramsr[   r[   r\   
set_params   s    
zMockClassifier.set_params)r   )NN)F)__name__
__module____qualname____doc__r]   re   rj   rl   rm   predict_probapredict_log_probadecision_functionrq   rt   rv   r[   r[   r[   r\   rV   g   s   


rV   c                   @   s   e Zd ZdZedd ZdS )LinearSVCNoScorez0A LinearSVC classifier that has no score method.c                 C   s   t d S rW   )AttributeErrorrZ   r[   r[   r\   rq      s    zLinearSVCNoScore.scoreN)rw   rx   ry   rz   propertyrq   r[   r[   r[   r\   r~      s   r~   rn      )rn   rn   r   r   c                    s*   t   fddtt D ks&J d S )Nc                    s   g | ]} | qS r[   r[   .0igridr[   r\   
<listcomp>       z3assert_grid_iter_equals_getitem.<locals>.<listcomp>)listranger^   r   r[   r   r\   assert_grid_iter_equals_getitem   s    r   klass
   n_iterz input, error_type, error_messagez1Parameter .* a dict or a list, got: 0 of type intfooz Parameter .* is not a dict \(0\)z}Parameter (grid|distribution) for parameter 'foo' (is not|needs to be) (a list or a numpy array|iterable or a distribution).*c                 C   s:   t j||d | | W d    n1 s,0    Y  d S )Nmatch)pytestraises)r   inputZ
error_typeerror_messager[   r[   r\   test_validate_parameter_input   s    r   c                  C   s  dg di} t | }t|ts"J t|ts0J t|dks@J t| ddgg dd}t |}t|dksrJ tdD ]>}td	d
 |D }|tdd
 t|d |d D kszJ qzt| t i }t|dksJ t	|i gksJ t| t
t |d  W d    n1 s0    Y  t dddgii ddgig}t|dksVJ t	|ddiddii ddigks|J t| d S )Nr   rn   r      r      r   )Zhamspameggsr   bar   c                 s   s"   | ]}t tt|  V  qd S rW   )tupler   sorteditemsr   pr[   r[   r\   	<genexpr>   r   z&test_parameter_grid.<locals>.<genexpr>c                 s   s   | ]\}}d |d|fV  qdS )r   r   Nr[   )r   xyr[   r[   r\   r      s   r   rn   Cr         ?)r/   
isinstancer   r   r^   r   r   setr   r   r   r   
IndexError)Zparams1Zgrid1Zparams2Zgrid2r   ZpointsemptyZ	has_emptyr[   r[   r\   test_parameter_grid   s2    
(&r   c                  C   s   t  } t| dg diddd}tj}t t_|tt |t_|jj	dksNJ t
|jd jg d |tt |t |t |t d|_tt |tt W d    n1 s0    Y  d S )NrY   r   r   r   cvverboseZparam_foo_paramsklearn)rV   r(   sysstdoutr   re   rc   r   best_estimator_rY   rS   cv_results_datarq   r{   r}   rl   scoringr   r   
ValueError)clfgrid_searchZ
old_stdoutr[   r[   r\   test_grid_search   s    


r   c                  C   s   t dt fg} dt t gi}t| |dd}|tt |jd }t|d tsVJ t|d tshJ t	|d drzJ t	|d drJ |d |j
usJ |d |j
usJ t	|d d drJ t	|d d drJ d S )N	regressorr   r   Zparam_regressorr   rn   Zcoef_)r<   r   r   r(   re   rc   r   r   r   hasattrr   )pipe
param_gridr   Zregressor_resultsr[   r[   r\   test_grid_search_pipeline_steps   s    
r   SearchCVc                 C   s  t ddd}t dgd dgd  }tddgd}| |d	g d
iddd}d}tjt|d& |j||t 	dd W d    n1 s0    Y  d}tjt|d. |j||t 	dt 
dd W d    n1 s0    Y  |j||t 	dt 
dd d S )Nd   r   r      rn   r   r   )Zexpected_fit_paramsrY   r   r   raiser   error_scorez0Expected fit parameter\(s\) \['eggs'\] not seen.r   )r   z)Fit parameter spam has length 1; expected)r   r   )r_   arangereshapearrayrJ   r   r   AssertionErrorre   oneszeros)r   rc   r   r   searchererr_msgr[   r[   r\   test_SearchCV_with_fit_params   s    4<r   c                  C   s   t dd} tddd\}}g d}tdd}t| d|idd}||| t|d|idd}||| |j|jksxJ ||||||ksJ t|d|i}tjt	d	d
 |dgg W d    n1 s0    Y  d S )Nr   random_stater   r   centers皙?rn   r   r   accuracyr   z
no scoringr   rn   )
rC   r   r~   r(   re   best_params_rq   r   r   	TypeError)r   rc   r   CsZclf_no_scorer   Zgrid_search_no_scorer[   r[   r\   test_grid_search_no_score  s    

r   c                  C   s   t ddddd\} }tdd}ddgi}t||d d	| |}t||d
d	| |}tt |dd	| |}t||dd	| |}|| |}|| |}	|| |}
|| |}|dk sJ |	dk sJ ||	ksJ t|	| t||
 d S )Nr   r   皙?r   	n_samples	n_classesZflip_yr   r   r   r   r   r   roc_aucro   )r   rC   r(   re   r~   rq   rQ   )rc   r   r   r   Zsearch_no_scoringZsearch_accuracyZsearch_no_score_method_aucZ
search_aucZscore_no_scoringZscore_accuracyZscore_no_score_aucZ	score_aucr[   r[   r\   test_grid_search_score_method+  s(    


r   c               	   C   s   t jd} tdddd\}}| ddd}tdd}ddgi}t tdtdd	t	 g}d
}|D ]\}t
|||d}	tjt|d |	|| W d    n1 s0    Y  |	j|||d qbt t g}
|
D ]}t
|||d}	|	|| qd S )Nr      r   )r   r   r   r   r   r   rn   n_splitsz*The 'groups' parameter should not be None.r   r   )groups)r_   randomRandomStater   randintrC   r-   r.   r)   r*   r(   r   r   r   re   r2   r3   )rngrc   r   r   r   r   Z	group_cvs	error_msgr   gsZnon_group_cvsr[   r[   r\   test_grid_search_groupsG  s(    

*r   c                  C   s   t ddd} t dgd dgd  }g d}ttddd|i}|| | t|jj	|j	 tt
 d	d
dgi}|| | t|drJ ttddd|i}t|drJ ttddd|idd}|| | t|drJ d S )Nr   r   r   r   rn   r   r   r   alpharo          @ra   F)refit)r_   r   r   r   r(   rC   re   rS   r   ra   r   r   )rc   r   r   r   r[   r[   r\   test_classes__propertyf  s    r   c                  C   sh   t  } t| ddgidd}|tt t|ds4J t| ddgiddd}|tt t|dsdJ d S )NrY   rn   r   r   r   r   )r   r   )rV   r(   re   rc   r   r   r1   )r   r   random_searchr[   r[   r\   test_trivial_cv_results_attr  s    r   c            	   
   C   sB  t  } d ddgfD ]}t| dg diddd}|tt t|dsXt|d	rXt|d
s\J dD ]~}d| d}d| d}tjt|d}t	||t W d    n1 s0    Y  t
|jjtsJ |t|jjv s`J q`qd}dD ]R}tjt|d. t| i |ddddtt W d    q1 s20    Y  qd S )Nr   	precisionrY   r   Fr   r   r   r   best_index_r   )rj   r{   r|   rl   rm   zhas no attribute ''z`refit=False`. z9 is available only after refitting on the best parametersr   zIFor multi-metric scoring, the parameter refit must be set to a scorer key)Trecallr   )accprec)r   r   )rV   r(   re   rc   r   r   r   r   r   getattrr   value	__cause__strr   )	r   r   r   fn_name	outer_msg	inner_msg	exec_infor   r   r[   r[   r\   test_no_refit  s6    
,r  c                  C   sl   t dddd\} }t }t|dddgi}tt$ || d d | W d    n1 s^0    Y  d S )	N   r   r   r   
n_featuresr   r   r   ro      )r   rC   r(   r   r   r   re   )X_y_r   r   r[   r[   r\   test_grid_search_error  s
    r  c                  C   sr   t dddd\} }dgdgdgd}td	d
}t||}|| | tdddd}|| | t|j|jj d S )Nr  r   r   r	  ro   rbfr   )r   kernelgammaautor  )r   rB   r(   re   rS   Z
dual_coef_r   )r  r  
param_dictr   r   r[   r[   r\   test_grid_search_one_grid_point  s    

r  c                  C   sB   t  } d }t| dtddidd}|tt |jjdks>J d S )NrY   rn   r   r   r   )rV   r(   r   re   rc   r   r   rY   )r   r   r[   r[   r\   /test_grid_search_when_param_grid_includes_range  s
    r  c                  C   s  t dddd\} }ddi}tdd}td	}t||}tjt|d
 || | W d    n1 sh0    Y  dg i}t }td}t||}tjt	|d
 || | W d    n1 s0    Y  ddi}tdd}td}t||}tjt|d
 || | W d    n1 s&0    Y  dt
di}t }t||}tt	 || | W d    n1 s|0    Y  d S )Nr   r   r   r	  r   rn   r  r  zParameter grid for parameter 'C' needs to be a list or a numpy array, but got 1 (of type int) instead. Single values need to be wrapped in a list with one element.r   zIParameter grid for parameter 'C' need to be a non-empty sequence, got: []z1,2,3zParameter grid for parameter 'C' needs to be a list or a numpy array, but got '1,2,3' (of type str) instead. Single values need to be wrapped in a list with one element.)r   r   )r   rB   reescaper(   r   r   r   re   r   r_   r   )rc   r   r  r   r   searchr[   r[   r\   test_grid_search_bad_param_grid  s<    

*
*

,
r  csr_containerc           	      C   s   t dddd\}}t }t|dddgi}||d d |d d  ||dd  }|jj}| |}t }t|dddgi}||d d  |d d  ||dd  }|jj}t	||kd	ksJ ||ksJ d S )
Nr  r   r   r	  r   r   ro   r  g?)
r   rC   r(   re   rj   r   r   Ztocoor_   mean)	r  r  r  r   r   y_predr   y_pred2C2r[   r[   r\   test_grid_search_sparse  s     r   c                 C   sP  t dddd\}}t }t|dddgidd	}||d d
 |d d
  ||d
d  }|jj}| |}t }t|dddgidd	}||d d
 |d d
  ||d
d  }|jj}t|| ||ksJ dd }	t|	dd}
t|dddgi|
d	}||d d
 |d d
  ||d
d  }|jj}||ksBJ t|| d S )Nr  r   r   r	  r   r   ro   f1r   r  c                 S   s   t | | S rW   )r"   )Zy_true_Zy_pred_r[   r[   r\   f1_loss-  s    z0test_grid_search_sparse_scoring.<locals>.f1_lossF)Zgreater_is_better)	r   rC   r(   re   rj   r   r   rS   r#   )r  r  r  r   r   r  r   r  r  r"  ZF1LossZy_pred3ZC3r[   r[   r\   test_grid_search_sparse_scoring  s,    
r#  c            	      C   s   t dddd\} }t| d d | d d j}|d d }tdd}t|dd	d
gi}||| |jdksrJ t| dd  | d d j}|dd  }||}t	||kdksJ t
t  || | W d    n1 s0    Y  d S )Nr  r   r   r	  r  precomputedr  r   r   ro   )r   r_   dotri   rB   r(   re   best_score_rj   r  r   r   r   tolist)	r  r  K_trainy_trainr   r   ZK_testZy_testr  r[   r[   r\   #test_grid_search_precomputed_kernel:  s    

r+  c                  C   sj   t d} t d}tdd}t|dddgi}tt || | W d    n1 s\0    Y  d S )N)r      )r   r$  r%  r   r   ro   )	r_   r   r   rB   r(   r   r   r   re   )r)  r*  r   r   r[   r[   r\   3test_grid_search_precomputed_kernel_error_nonsquareW  s    


r-  c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
BrokenClassifierz*Broken classifier that cannot be fit twiceNc                 C   s
   || _ d S rW   	parameterrZ   r0  r[   r[   r\   r]   e  s    zBrokenClassifier.__init__c                 C   s   t | drJ d| _d S )Nhas_been_fit_T)r   r2  rZ   rc   r   r[   r[   r\   re   h  s    zBrokenClassifier.fitc                 C   s   t |jd S rf   r_   r   rh   rk   r[   r[   r\   rj   l  s    zBrokenClassifier.predict)N)rw   rx   ry   rz   r]   re   rj   r[   r[   r[   r\   r.  b  s   
r.  z1ignore::sklearn.exceptions.UndefinedMetricWarningc                  C   sX   t ddd} t dgd dgd  }tt dddgigddd	}|| | d S )
Nr   r   r   r   rn   r0  r   Tr   r   )r_   r   r   r   r(   r.  re   )rc   r   r   r[   r[   r\   
test_refitp  s    r6  c                  C   sd   dd } t dddd\}}ttdddg d	id
| d}||| |jdksRJ t|dr`J dS )z^
    Test refit=callable, which adds flexibility in identifying the
    "best" estimator.
    c                 S   sr   t dddd\}}ttdddg didd	d
}||| |jdksJJ |j D ]}|| v sTJ qT| d  S )z
        A dummy function tests `refit=callable` interface.
        Return the index of a model that has the least
        `mean_test_score`.
        r   r   *   r	  r   r   {Gz?r   rn   r   Tr5  r   mean_test_score)r   r(   rC   re   r   r   keysargmin)
cv_resultsrc   r   r   keyr[   r[   r\   refit_callable  s    
z+test_refit_callable.<locals>.refit_callabler   r   r7  r	  r   r   r8  r   r5  r   r'  N)r   r(   rC   re   r   r   )r?  rc   r   r   r[   r[   r\   test_refit_callable~  s    
r@  c                  C   sv   dd } t dddd\}}ttdddd	d
gid| d}tjtdd ||| W d   n1 sh0    Y  dS )zb
    Test implementation catches the errors when 'best_index_' returns an
    invalid result.
    c                 S   s   dS )zT
        A dummy function tests when returned 'best_index_' is not integer.
        Nr[   r=  r[   r[   r\   refit_callable_invalid_type  s    zEtest_refit_callable_invalid_type.<locals>.refit_callable_invalid_typer   r   r7  r	  r   r   r   rn   r   r5  z&best_index_ returned is not an integerr   N)r   r(   rC   r   r   r   re   )rB  rc   r   r   r[   r[   r\    test_refit_callable_invalid_type  s    
rC  out_bound_value	search_cvc                    sz    fdd}t dddd\}}|tdddd	d
gid|d}tjtdd ||| W d   n1 sl0    Y  dS )zg
    Test implementation catches the errors when 'best_index_' returns an
    out of bound result.
    c                    s    S )zV
        A dummy function tests when returned 'best_index_' is out of bounds.
        r[   rA  rD  r[   r\   refit_callable_out_bound  s    z?test_refit_callable_out_bound.<locals>.refit_callable_out_boundr   r   r7  r	  r   r   r   rn   r   r5  zbest_index_ index out of ranger   N)r   rC   r   r   r   re   )rD  rE  rG  rc   r   r   r[   rF  r\   test_refit_callable_out_bound  s    
rH  c                  C   sr   dd } t dddd\}}ttdd}ttdd	d
g di|| d}||| |jdks`J t|drnJ dS )zC
    Test refit=callable in multiple metric evaluation setting
    c                 S   s   d| v sJ | d   S )z
        A dummy function tests `refit=callable` interface.
        Return the index of a model that has the least
        `mean_test_prec`.
        Zmean_test_prec)r<  rA  r[   r[   r\   r?    s    z8test_refit_callable_multi_metric.<locals>.refit_callabler   r   r7  r	  r   )ZAccuracyr   r   r   r8  r5  r   r'  N)r   r#   r    r(   rC   re   r   r   )r?  rc   r   r   r   r[   r[   r\    test_refit_callable_multi_metric  s    	
rI  c                  C   s   t ddddd} t dddd}d	d
 }dd }t||dgd}t|dg di}|| |tt t	|ds~J d S )N,  r   r   r   r   i        c                 S   s   | j dd  dkS )Nrn   )r   r   r   rg   r   r[   r[   r\   check_X  s    z#test_gridsearch_nd.<locals>.check_Xc                 S   s   | j dd  dkS )Nrn   )rK  rL  rg   rM  r[   r[   r\   check_y  s    z#test_gridsearch_nd.<locals>.check_yre   )rN  rO  methods_to_checkrY   r   r   )
r_   r   r   rJ   r(   re   rq   rc   r   r   )ZX_4dZy_3drN  rO  r   r   r[   r[   r\   test_gridsearch_nd  s    rQ  c                  C   s   t ddd} t dgd dgd  }tdd dgd	}td
d}t|dg di|d}||  |	| | t
|dsJ d S )Nr   r   r   r   rn   c                 S   s
   t | tS rW   r   r   rM  r[   r[   r\   <lambda>  r   z test_X_as_list.<locals>.<lambda>re   )rN  rP  r   r   rY   r   r   r   r_   r   r   r   rJ   r,   r(   re   r(  rq   r   rc   r   r   r   r   r[   r[   r\   test_X_as_list  s    
rV  c                  C   s   t ddd} t dgd dgd  }tdd dgd	}td
d}t|dg di|d}|| | 	| | t
|dsJ d S )Nr   r   r   r   rn   c                 S   s
   t | tS rW   rR  rM  r[   r[   r\   rS  $  r   z test_y_as_list.<locals>.<lambda>re   )rO  rP  r   r   rY   r   r   r   rT  rU  r[   r[   r\   test_y_as_list  s    
rW  c                     s   t t fg} z"ddlm}m} | ||f W n ty>   Y n0 tddd}t	dgd dgd  }| D ]|\  || }} fdd}fd	d
}t
||d}	t|	dg di}
|
|||| |
| t|
dspJ qpd S )Nr   )	DataFrameSeriesr   r   r   rn   c                    s
   t |  S rW   r   rM  )InputFeatureTyper[   r\   check_df>  s    z#test_pandas_input.<locals>.check_dfc                    s
   t |  S rW   rZ  rM  )
TargetTyper[   r\   check_seriesA  s    z'test_pandas_input.<locals>.check_series)rN  rO  rY   r   r   )rK   pandasrX  rY  appendImportErrorr_   r   r   r   rJ   r(   re   rq   rj   r   )typesrX  rY  rc   r   ZX_dfZy_serr\  r^  r   r   r[   )r[  r]  r\   test_pandas_input-  s"    

rc  c                  C   s   t ddd\} }tdddd}ddg}d	D ]<}t|tg d
d||d}|| | |jd dks*J q*t|tg d
ddd}|| | |jd dksJ t|tg d
dd}||  |jd dksJ d S )N2   r   r   r   r   rn   )r   initZn_initadjusted_rand_scorefowlkes_mallows_score)rg  rh  )r   r   r   )
n_clusters)r   r   r   ri  r   r   r   r   r   )r   r   r(   dictre   r   )rc   r   kmr   r   r   r[   r[   r\   test_unsupervised_grid_searchL  s"    
rn  c                  C   st   dd } t ddddgddgddggd\}}tt tg dd| d	}|| |jd
 dksbJ |jdkspJ d S )Nc                 S   s   | j dkrdS dS )Nr   r7  r   	bandwidth)	estimatorrc   r[   r[   r\   custom_scoringk  s    z2test_gridsearch_no_predict.<locals>.custom_scoringr   rn   r   )cluster_stdr   r   r8  ro  rj  rp  r7  )r   r(   r9   rl  re   r   r'  )rr  rc   _r  r[   r[   r\   test_gridsearch_no_predicth  s    $
ru  c                  C   s   ddgt ddd} t| ddd}dd	 |D }t|dks@J |D ]2}|d
 dv sXJ d|d   krpdksDn J qDdg di} t| ddd}dd	 |D dd	 |D ksJ dt ddi} t| ddd}dd	 |D dd	 |D ksJ d S )Nr  linearr   rn   )r  r   r   )param_distributionsr   r   c                 S   s   g | ]}|qS r[   r[   r   r   r[   r[   r\   r     r   z&test_param_sampler.<locals>.<listcomp>r  )r  rv  r   )r   rn   r   r   r   r   r   rK     	   r   r   c                 S   s   g | ]}|qS r[   r[   rx  r[   r[   r\   r     r   c                 S   s   g | ]}|qS r[   r[   rx  r[   r[   r\   r     r   )r   r0   r^   )rw  samplersamplessampler[   r[   r\   test_param_samplery  s&      r~  c                    s   | j  t fdd|D s J  fdd|D |ks:J t fdd|D rTJ t fdd|D snJ | jr~| j ndg}|D ]} d|  jtjksJ qd S )	Nc                 3   s    | ]}t  | tjjV  qd S rW   r   r_   maMaskedArray)r   paramrA  r[   r\   r     r   z/check_cv_results_array_types.<locals>.<genexpr>c                    s   i | ]}| | j jqS r[   )dtypekindr   r>  rA  r[   r\   
<dictcomp>  s   z0check_cv_results_array_types.<locals>.<dictcomp>c                 3   s    | ]}t  | tjjV  qd S rW   r  r  rA  r[   r\   r     r   c                 3   s(   | ] }| d s | jtjkV  qdS )ZrankN)
startswithr  r_   float64r  rA  r[   r\   r     s   
rq   zrank_test_%s)	r   allanymultimetric_scorer_r;  r  r_   Zint32)r  
param_keys
score_keysexpected_cv_results_kindsZscorer_keysr>  r[   rA  r\   check_cv_results_array_types  s    
r  r[   c                    sJ   || | }t t  t|d  t fdd|| D sFJ d S )N)ru   c                 3   s   | ]} | j fkV  qd S rW   rg   r  r=  n_candr[   r\   r     r   z(check_cv_results_keys.<locals>.<genexpr>)rS   r   r;  r  )r=  r  r  r  Z
extra_keysall_keysr[   r  r\   check_cv_results_keys  s    r  c                     sP  t dddd\} }d}tdgddgd	dgd
tdgddgdg}d}d}|}tt d|dd}|| | |j t d dksJ  fdd|D sJ  fdd|D sJ ddddd}t|||| t ||| |j  fddt	|D }	t|	sJ t
|	dksJ  fddt	|D }
t|
s:J t
|
dksLJ d S )Nrd  r   r7  r	  r   r  rn   r   r   r  r   r  polyr   r  Zdegreeparam_Cparam_degreeparam_gammaparam_kernelr:  mean_train_scorerank_test_scoreZsplit0_test_scoreZsplit1_test_scoreZsplit2_test_scoreZsplit0_train_scoreZsplit1_train_scoreZsplit2_train_scorestd_test_scorestd_train_scoremean_fit_timestd_fit_timemean_score_timestd_score_timer   T)r   r   return_train_scorer  c                 3   s&   | ]}|d krt  | dkV  qdS )r  r   Nr  r   krA  r[   r\   r     r   z.test_grid_search_cv_results.<locals>.<genexpr>c                 3   s.   | ]&}d |vr|dkrt  | dkV  qdS )timer  rn   Nr  r  rA  r[   r\   r     s   r   fOc                    sH   g | ]@} d  | dkr d j | oB d j | oB d j |  qS )r  r  r  r  r  maskr   rA  r[   r\   r     s   z/test_grid_search_cv_results.<locals>.<listcomp>c                    sJ   g | ]B} d  | dkr d j |  oD d j |  oD d j | qS )r  r  r  r  r  r  r   rA  r[   r\   r     s   )r   rl  r(   rB   re   r   r  r  r  r   r^   )rc   r   Zn_grid_pointsru   r  r  n_candidatesr  r  Zpoly_resultsZrbf_resultsr[   rA  r\   test_grid_search_cv_results  sZ    


	
	r  c            	         s   t dddd\} }d}dgtddtd	dd
dgddgdg}d}d}|}tt |d|dd}|| | |j ddddd}t|||| t ||| t fddt	|D sJ t fddt	|D sJ d S )Nrd  r   r7  r	     r  r   )scaler   r  r  r   r   r  r  r  T)r   r   rw  r  r  r   r  c                 3   sJ   | ]B} d  | dkr d j | o@ d j | o@ d j |  V  qdS )r  r  r  r  r  Nr  r   rA  r[   r\   r   ;  s   z0test_random_search_cv_results.<locals>.<genexpr>c                 3   sL   | ]D} d  | dkr d j |  oB d j |  oB d j | V  qdS )r  r  r  r  r  Nr  r   rA  r[   r\   r   D  s   )
r   r
   r1   rB   re   r   r  r  r  r   )	rc   r   n_search_iterru   r  r  r  r  r  r[   rA  r\   test_random_search_cv_results
  s@    	r  zSearchCV, specialized_paramsr   r   )rw  r   c                    s  t ddgddgddgddggddddd\}}tj|jd td}d|t|dkd d d d < d|t|dkd d d d < || g| |gg}t |d	d
}| f i ||  || t fddt	 j
D } jd d } jd d }	t fddt	 j
D }
 jd d } jd d } jd d dksNJ t|ddg t|
ddg |tt|ksJ |	tt|ksJ |tdksJ |tdksJ d S )Nr   rn   r   FP   )r   r   rs  shuffler   r  r   T)rq  r   r  c                    s   g | ]} j d |  d qS )split%d_test_scorer   r   r   sr  r[   r\   r   o  s   z+test_search_default_iid.<locals>.<listcomp>r:  r  c                    s   g | ]} j d |  d qS )zsplit%d_train_scorer   r  r  r  r[   r\   r   x  s   r  r  r  gUUUUUU?)r   r_   r   rh   boolwhererB   re   r   r   	n_splits_r   rP   r   approxr  Zstd)r   specialized_paramsrc   r   r  r   Zcommon_paramsZtest_cv_scoresZ	test_meanZtest_stdZtrain_cv_scoresZ
train_meanZ	train_stdr[   r  r\   test_search_default_iidO  sF    

	  

r  c                  C   s   t dddd\} }d}tdgddgd	dgd
tdgddgdg}g }ttttdddfD ].}tt |||dd}|| | || q\t	|  d S )Nrd  r   r7  r	  r   r  rn   r   r   r  r  r   r  r   r   r   r   F)r   r   r   r   )
r   rl  r#   r    r%   r(   rB   re   r`  *compare_cv_results_multimetric_with_single)rc   r   r   ru   Zgrid_searchesr   r   r[   r[   r\   'test_grid_search_cv_results_multimetric  s2    r  c                  C   s   t dddd\} }d}d}ttdddtjd	d
dddd}dD ]}g }dD ]\}|rnd}t|trhdn|}nd}t|dd}	t|	|||||d
d}
|
| | |	|
 qNt
|  t|d
 |d | qBd S )Nrd  r   r7  r	  r   r  rn   r   r   )base)r   r  TF)r  r   r   Tr   F)probabilityr   )r   r   rw  r   r   r   )r   rl  r_   Zlogspacer   r   rB   r1   re   r`  r  )compare_refit_methods_when_refit_with_acc)rc   r   r   r  ru   r   Zrandom_searchesr   r  r   r   r[   r[   r\   )test_random_search_cv_results_multimetric  s6    $	r  c                    s   | j s
J tt| jd | j dd |j D }|dd |j D  t fdddD shJ tj	
dd   D d	d | D  d
S )zCompare multi-metric cv_results with the ensemble of multiple
    single metric cv_results from single metric grid/random searchr  c                 S   s    i | ]\}}t d d||qS )_score$Z	_accuracyr  subr   r  vr[   r[   r\   r    s   z>compare_cv_results_multimetric_with_single.<locals>.<dictcomp>c                 S   s    i | ]\}}t d d||qS )r  Z_recallr  r  r[   r[   r\   r    r   c                 3   s    | ]}t  | d kV  qdS )rn   N)r_   r  r  Zcv_results_multir[   r\   r     s   z=compare_cv_results_multimetric_with_single.<locals>.<genexpr>)r  r  r  r  c                 S   s    i | ]\}}| d s||qS _timeendswithr  r[   r[   r\   r    r   c                 S   s    i | ]\}}| d s||qS r  r  r  r[   r[   r\   r    r   N)r  rS   r   r  r   r   updater  r_   testingassert_equal)search_multi
search_accZ
search_recZcv_results_acc_recr[   r  r\   r    s$    

r  c                 C   s   |j |ksJ |r"| j dks0J n| j r,J dS tdddd\}}dD ]"}tt| ||t||| qFt| ||||| dD ]}t| |t||ksJ qdS )	zDCompare refit multi-metric search methods with single metric methodsr   Nr   r   r7  r	  )rj   r{   r|   )r   r'  r   )r   r   rQ   r   rq   )r  r  r   rc   r   methodr>  r[   r[   r\   r    s    
r  	max_depthr   )rq  rw  rq  r   c                 C   s   t dddd\}}| || d| jj d}d}tjt|d}| | W d    n1 s`0    Y  t|j	j
ts|J |t|j	j
ksJ d S )	Nr   r   r7  r	  r   z"' has no attribute 'score_samples'z@'DecisionTreeClassifier' object has no attribute 'score_samples'r   )r   re   	__class__rw   r   r   r   score_samplesr   r   r  r  )rE  rc   r   r  r  r  r[   r[   r\   "test_search_cv_score_samples_error  s    (r  T)Znoveltyn_neighborsr   )rq  rw  r   )rq  r   r   c                 C   s   t jd}d}d}t|| }|| }t|dddgddggdddd }t j||jdd	|dfd
gdd}t dg| }d|| d < | || t	| 
|| j
| d S )Nr7  rJ  g333333?r   r   r   )r   r
  r   rs  r   ir   )lowhighsizeZaxisrn   r   )r_   r   r   intr   Zconcatenater   r   re   rP   r  r   )rE  r   r   Zoutliers_fractionZ
n_outliersZ	n_inliersrc   Zy_truer[   r[   r\   #test_search_cv_score_samples_method)  s*    "r  c                  C   s   t ddd\} }dg di}tt |dd}tt d|dd	}||fD ]}|| | |j}t|d
 d |d
 d  t|d d |d d  t|d
 d |d
 d rJ t|d d |d d rJ t|jd g d qFd S )Nrd  r7  re  r   )rn   gjt?MbP?T)r   r  r   )r   rw  r  r:  r   rn   r  r   r  )rn   rn   r   )	r   r(   rB   r1   re   r   rQ   r_   Zallclose)rc   r   r   r   r   r  r=  r[   r[   r\   (test_search_cv_results_rank_tie_breakingY  s,    
r  c                  C   sx   dgdgdgdgdggg d } }t  t f}ddd gi}t }|D ].}t|||d	| |}t|jd
 dd g qDd S )Nrn   r   r   r   r   )r   r   r   r   rn   r   r   r   Zparam_random_state)rH   rG   r,   r(   re   rS   r   )rc   r   
estimatorsest_parametersr   estr   r[   r[   r\   !test_search_cv_results_none_param{  s    "r  z+ignore::sklearn.exceptions.FitFailedWarningc                  C   s.  t dd} dgdgdgdgg}g d}t| dddgiddd	}t| dddgidddd
}||fD ]}||| dD ]4}t|j| dksJ t|j| dk stJ qtdD ]H}|j| d dksJ |j| d dksJ t|j| dk sJ qt|dsJ t|j	t
sJ |j	dks`J q`d S )Nr   r   rn   r   r   r   )r   rn   rn   r   r   r   )r   r   r   )r  r  )r  r  rp   refit_time_)rC   r(   r1   re   r_   r  r   r   r   r  float)Zsvcrc   r   r   rsr  r>  r[   r[   r\   test_search_cv_timing  s2    
r  c               	      sh  d} t dd}tddd\}}g d}dD ]6}t|d|i|| d	||j}t| }d
tdd t| D  }t	t
||sJ t| d}	j} t|D ]\ }
|j|
d t
 fddt| D }t|	||D ]x\}\}}||| ||  |dkr*t|| ||| }n&|dkrP||| }t|| |}t|||  qqq*d S )Nr   r   r   r   r   r   )r!  r   r   )r   r   )r:  r  c                 s   s   | ]}d | V  qdS )r  Nr[   )r   Zcv_ir[   r[   r\   r     s   z9test_grid_search_correct_score_results.<locals>.<genexpr>r   )r   c                    s   g | ]}j d |    qS r  r  r  Zcandidate_ir   r[   r\   r     s   z:test_grid_search_correct_score_results.<locals>.<listcomp>r!  r   )rC   r   r(   re   r   r   r;  r   r   r  r_   isinr2   r  	enumeraterv   r   splitr"   rj   r}   r&   rQ   )r   r   rc   r   r   rq   r=  Zresult_keysZexpected_keysr   r   Z	cv_scoresr   traintestcorrect_scoredecr[   r  r\   &test_grid_search_correct_score_results  s:    






r  c                  C   s   t  } t| dg diddd}|tt tt|}t|	t|	t t
| dg didddd}|tt tt|}t|	t|	t d S )NrY   r   Tr   r   r   )r   r   r   )rV   r(   re   rc   r   pickleloadsdumpsrR   rj   r1   )r   r   Zgrid_search_pickledr   Zrandom_search_pickledr[   r[   r\   test_pickle  s    r   c                  C   s  t ddd\} }dg di}t }tddtddg}|D ]}t|||d}|| | |jd }tt|D ]v}|j	f i ||  t
|| |D ]L\}	\}
}|| |
 ||
  || | || }t||jd	|	  |  qqnq:|D ]}t|||d
d}|| | |jd }tt|D ]z}|j	f i ||  t
|| |D ]N\}	\}
}|| |
 ||
  || | || }t||jd	|	  |  qJq"qd S )NTr   )Zreturn_indicatorr   r  )rn   r   r   r   r   r   ru   r  r   )r   r   )r   r,   rH   rG   r(   re   r   r   r^   rv   r  r  rq   rQ   r1   )rc   r   r  r   r  r  r   Z
res_paramscand_ir   r  r  r  r   r[   r[   r\   &test_grid_search_with_multioutput_data  s@    


r  c                  C   sL   t ddd} g d}tdd}t|i dd| |}t|d	rHJ d S )
Nr,  r   r   r   r   rn   rn   rn   F)r  r   r   r{   )r_   r   r   rB   r(   re   r   rc   r   r   r   r[   r[   r\   test_predict_proba_disabled  s
    
r  c                  C   st   t jdt jddd} t j| dd d f< g d}tdtdt jd	fd
t fg}t|dg didd	| | d S )Nr,  r  r   r   r   r  Zimputerr  )ZstrategyZmissing_values
classifierZclassifier__foo_paramr   r   )
r_   r   r  r   nanr<   r   rV   r(   re   )rc   r   r   r[   r[   r\   test_grid_search_allows_nans!  s    r  c                   @   s:   e Zd ZdZdZdddZdddZdd	 Zdd
dZdS )FailingClassifierz,Classifier that raises a ValueError on fit()r   Nc                 C   s
   || _ d S rW   r/  r1  r[   r[   r\   r]   4  s    zFailingClassifier.__init__c                 C   s   | j tjkrtdd S )Nz%Failing classifier failed as required)r0  r	  FAILING_PARAMETERr   r3  r[   r[   r\   re   7  s    zFailingClassifier.fitc                 C   s   t |jd S rf   r4  rk   r[   r[   r\   rj   ;  s    zFailingClassifier.predictc                 C   s   dS )Nrp   r[   rb   r[   r[   r\   rq   >  s    zFailingClassifier.score)N)N)NN)	rw   rx   ry   rz   r
  r]   re   rj   rq   r[   r[   r[   r\   r	  /  s   

r	  c                     s  t dddd\} }t }t|dg digddd	d
tjdtjd}tjt|d 	| | W d    n1 st0    Y  t
jd }fdd t fddt|D sJ t|dg digddtdd
tjdtjd}tjt|d 	| | W d    n1 s0    Y  t
jd }t fddt|D sTJ jd }|d dkrz|d dks~J ||j dksJ j|jksJ d S )Nr,  r   r   r	  r0  r   rn   r   r   Frp   r   r   r   z5 fits failed.+total of 15.+The score on these train-test partitions for these parameters will be set to 0\.0.+5 fits failed with the following error.+ValueError.+Failing classifier failed as requiredflagsr   ru   c                    s    t  fddtjD S )Nc                    s   g | ]} j d |   qS r  r  r  )r   r   r[   r\   r   f  r   zPtest_grid_search_failing_classifier.<locals>.get_cand_scores.<locals>.<listcomp>)r_   r   r   r  r   )r   r  r\   get_cand_scoresd  s    z<test_grid_search_failing_classifier.<locals>.get_cand_scoresc                 3   s4   | ],}j d  | tjkrt |dkV  qdS )param_parameterrp   N)r   r	  r
  r_   r  r   r  r  r   r[   r\   r   j  s
   z6test_grid_search_failing_classifier.<locals>.<genexpr>r  z5 fits failed.+total of 15.+The score on these train-test partitions for these parameters will be set to nan.+5 fits failed with the following error.+ValueError.+Failing classifier failed as requiredc                 3   s6   | ].}j d  | tjkrtt |V  qdS )r  N)r   r	  r
  r_   r  isnanr  r  r[   r\   r     s
   r  r   rn   r   )r   r	  r(   r  compileDOTALLr   warnsr   re   r^   r   r  r   r  r
  r   )rc   r   r   warning_messager  Zranksr[   r  r\   #test_grid_search_failing_classifierB  sV    *	,
 r  c                  C   s   t dddd\} }t }t|dtjgd igdd}tjd	tjd
}tjt	|d |
| | W d    n1 st0    Y  d S )Nr,  r   r   r	  r0  r   rp   r   zrAll the 15 fits failed.+15 fits failed with the following error.+ValueError.+Failing classifier failed as requiredr  r   r   r	  r(   r
  r  r  r  r   r   r   re   )rc   r   r   r   r  r[   r[   r\   )test_grid_search_classifier_all_fits_fail  s    r  c                  C   sn   t dddd\} }t }t|dg digddd	d
}tt || | W d    n1 s`0    Y  d S )Nr,  r   r   r	  r0  r  r   Fr   r  )r   r	  r(   r   r   r   re   r  r[   r[   r\   )test_grid_search_failing_classifier_raise  s    	r  c            	      C   sl  ddgg dddddgig} t | dd	}d}d
}d|||f }tjt|d t| W d    n1 sl0    Y  t | d
d	}t|}t|d
ksJ t| D ]}||v sJ qtt | dd	d
ksJ tdtdtdd} t | ddd}t|}t|dksJ dd |D }tt|dks0J t	dg dd}t |dd	}t|}t|dkshJ d S )Nr   rn   )abc)firstsecondthirdtwovaluesrz  r   ry  z}The total space of parameters %d is smaller than n_iter=%d. Running %d iterations. For exhaustive searches, use GridSearchCV.r     r   c   r7  )r   r   c                 S   s&   g | ]}d |d |d |d f qS )z	a%db%dc%dr  r  r   r[   r   r[   r[   r\   r     r   z7test_parameters_sampler_replacement.<locals>.<listcomp>r   rK  )
r0   r   r  UserWarningr   r^   r/   r   r   r	   )	ru   r{  r   Z	grid_sizeZexpected_warningr|  r%  Zhashable_samplesZparams_distributionr[   r[   r\   #test_parameters_sampler_replacement  s8    
&r)  c                  C   s   ddgi} t ddd}g d}ttdd| d	d
}t|drFJ ||| || || ddgi} ttdd| d	d
}t|drJ ||| t|drJ d S )NlossZlog_loss   r   r   r   r   r   rn   rn   rn   Zhinge)r*  r   rq  r   r   r{   )	r_   r   r   r(   r   r   re   r{   r|   )r   rc   r   r   r[   r[   r\   #test_stochastic_gradient_loss_param  s&    

r.  c                  C   sJ   t ddd} g d}tdd}t|dddgid	d
}|| | d S )Nr   r   r,  r   r   r   r   r   r   )r   r   )r_   r   r   rC   r(   re   r  r[   r[   r\   %test_search_train_scores_set_to_false  s
    
r/  c            	         s  d} d}t | dd\}}ttdddg dit|| dd	d
  || ttdddg dit|dd	d
}||| tt|d	dd||tsJ ttdddg dit|d	dd||d	d
}||| ttdddg dit|d	ddd	d
}||| dd }t	j
||j||j t	j
dd  j D dd |j D  ttdddg dit|d	dd	d
  || dD ]\i }tdD ]$ fddtdD |< qt|d |d  t|d |d  qd S )Nr   r   r   re  r   r   )r   r   g333333?)r   r   T)r   r   r  r   )r   r  r   c                 S   s   dD ]}|  | q| S )N)r  r  r  r  )pop)r=  r>  r[   r[   r\   _pop_time_keys:  s    z>test_grid_search_cv_splits_consistency.<locals>._pop_time_keysc                 S   s    i | ]\}}| d s||qS r  r  r  r[   r[   r\   r  Q  r   z:test_grid_search_cv_splits_consistency.<locals>.<dictcomp>c                 S   s    i | ]\}}| d s||qS r  r  r  r[   r[   r\   r  R  r   )r   r   r   r   )r   r  )r  r  r   c                    s"   g | ]} j d |f   qS )zsplit%d_%s_scorer  r  r   Zparam_iZ
score_typer[   r\   r   e  s   z:test_grid_search_cv_splits_consistency.<locals>.<listcomp>rn   r   r   )r   r(   rC   r7   re   r,   r   r  r   r_   r  r  r   r   r   rR   )	r   r   rc   r   Zgs2Zgs3Zgs4r1  Zper_param_scoresr[   r2  r\   &test_grid_search_cv_splits_consistency  st    







r3  c                  C   sH   t  } t| dg diddd}|tt ||t}tt| d S )NrY   r   r   r   r   )rV   r(   re   rc   r   rm   rl   rS   )r   r   ZX_round_tripr[   r[   r\   +test_transform_inverse_transform_round_tripn  s
    r4  c                     s   dd  fddG fdddt } tddtd	d
dd\ | dd }dddgidddgig}|j}|| t|D ]H}|d  r|dd  dkr|dvrt||t||ksJ d| qd S )Nc                 S   s   |j }t|  t|ksJ | D ]f}|ds"t| | | |< | | jjdkrnt|| | | d| d q"t	|| | | d| d q"d S )Nr  r  z	Checking )r   )
r   r   r;  r  r_   Z
asanyarrayr  r  rS   rP   )resultsgscvZexp_resultsr  r[   r[   r\   check_resultsx  s    
z-test_custom_run_search.<locals>.check_resultsc                    s   t | dd S )NTr  )r(   re   rk  )rc   r   r   r[   r\   fit_grid  s    z(test_custom_run_search.<locals>.fit_gridc                       s*   e Zd Z fddZfddZ  ZS )z.test_custom_run_search.<locals>.CustomSearchCVc                    s   t  j|fi | d S rW   superr]   rZ   rq  kwargsr  r[   r\   r]     s    z7test_custom_run_search.<locals>.CustomSearchCV.__init__c                    sd   |ddiddig} |dddgi |ddiddig} |dddgidddgig d S )Nr  rn   r   min_samples_splitr   r   r[   )rZ   evaluater5  r7  r9  r[   r\   _run_search  s    z:test_custom_run_search.<locals>.CustomSearchCV._run_search)rw   rx   ry   r]   rB  __classcell__r[   rA  r>  r\   CustomSearchCV  s   rD  r   r   r   r   )r   Zn_informativer   Tr8  r  rn   r   r?  r   r   r   rt  >   ra   r   r  r   r  zAttribute %s not equal)r5   rH   r   re   r   dirislowerr   )rD  Zmycvr6  r5  attrr[   )rc   r7  r   r9  r   r\   test_custom_run_searchw  s*    


rH  c                  C   sv   G dd dt } | t tt G dd dt }tjtdd" |t tt W d    n1 sh0    Y  d S )Nc                       s&   e Zd Z fddZdddZ  ZS )z;test__custom_fit_no_run_search.<locals>.NoRunSearchSearchCVc                    s   t  j|fi | d S rW   r:  r<  r>  r[   r\   r]     s    zDtest__custom_fit_no_run_search.<locals>.NoRunSearchSearchCV.__init__Nc                 [   s   | S rW   r[   )rZ   rc   r   r   
fit_paramsr[   r[   r\   re     s    z?test__custom_fit_no_run_search.<locals>.NoRunSearchSearchCV.fit)NN)rw   rx   ry   r]   re   rC  r[   r[   r>  r\   NoRunSearchSearchCV  s   rJ  c                       s   e Zd Z fddZ  ZS )z3test__custom_fit_no_run_search.<locals>.BadSearchCVc                    s   t  j|fi | d S rW   r:  r<  r>  r[   r\   r]     s    z<test__custom_fit_no_run_search.<locals>.BadSearchCV.__init__)rw   rx   ry   r]   rC  r[   r[   r>  r\   BadSearchCV  s   rK  z_run_search not implemented.r   )r5   rB   re   rc   r   r   r   NotImplementedError)rJ  rK  r[   r[   r\   test__custom_fit_no_run_search  s
    rM  c                  C   s   t ddt} dd | D  d}tt dg di| dd	}tjtd
d, |td | t	d |  W d    n1 s|0    Y  d S )Nr   r   c                 S   s   g | ]}|qS r[   r[   )r   ur[   r[   r\   r     r   z0test_empty_cv_iterator_error.<locals>.<listcomp>r   r   r  r9  r   r   r   n_jobszNNo fits were performed. Was the CV iterator empty\? Were there no candidates\?r   )
r,   r  rc   r1   r   r   r   r   re   r   )r   
train_sizeridger[   r[   r\   test_empty_cv_iterator_error  s    rT  c                  C   s   G dd dt } | dd}d}tt dg di|dd	}tjtd
d, |td | td |  W d    n1 sx0    Y  d S )Nc                   @   s   e Zd Zdd ZdS )z.test_random_search_bad_cv.<locals>.BrokenKFoldc                 _   s   dS )Nrn   r[   )rZ   argskwr[   r[   r\   get_n_splits  s    z;test_random_search_bad_cv.<locals>.BrokenKFold.get_n_splitsN)rw   rx   ry   rW  r[   r[   r[   r\   BrokenKFold  s   rX  r   r   r   r   rO  r   rP  zXcv.split and cv.get_n_splits returned inconsistent results. Expected \d+ splits, got \d+r   )	r,   r1   r   r   r   r   re   rc   r   )rX  r   rR  rS  r[   r[   r\   test_random_search_bad_cv  s    
rY  r  F)r   r   r   ry  r   c                 C   s  t ddd\}}G dd d}| t f| d|d|}tt}||| W d    n1 sf0    Y  |r|dd	gndg}t|t|ksJ t||D ]"\}	}
d
|
 dt|	j	v sJ q|j
d  }t|j
d }t|j
d | | t|j
d |  |k sJ d S )Nr   r   )r   r   c                   @   s    e Zd ZdZdd Zdd ZdS )zHtest_searchcv_raise_warning_with_non_finite_score.<locals>.FailingScorerz1Scorer that will fail for some split but not all.c                 S   s
   d| _ d S rf   )n_countsr   r[   r[   r\   r]     s    zQtest_searchcv_raise_warning_with_non_finite_score.<locals>.FailingScorer.__init__c                 S   s&   |  j d7  _ | j d dkr"tjS dS )Nrn   r   r   )rZ  r_   r  )rZ   rq  rc   r   r[   r[   r\   __call__  s    zQtest_searchcv_raise_warning_with_non_finite_score.<locals>.FailingScorer.__call__N)rw   rx   ry   rz   r]   r[  r[   r[   r[   r\   FailingScorer
  s   r\  r   )r   r   r  r  r  zOne or more of the z scores are non-finiter  r:  )r   rG   r   r  r(  re   r^   zipr  messager   maxr_   r  rS   r  )r   r  r  rc   r   r\  r   Zwarn_msgZset_with_warningmsgZdatasetZ	last_rankZnon_finite_maskr[   r[   r\   1test_searchcv_raise_warning_with_non_finite_score  s*    *ra  c            	      C   s   dd } t dddd\}}tdd}t|dd	d
gi| dd}||| g d}|D ]}d||jv sTJ qT||}t||}|||t	
|d ksJ d S )Nc                 S   s2   |  |}t||}|d |d |d |d dS )N)r   r   r   rn   )rn   r   rn   rn   tnfpfntp)rj   r!   )r   rc   r   r  cmr[   r[   r\   custom_scorer1  s    

zAtest_callable_multimetric_confusion_matrix.<locals>.custom_scorer(   r   r7  r	  r   r   r   rn   rf  r5  rd  zmean_test_{}rb  )r   rC   r(   re   formatr   rj   r!   rq   r   r  )	rj  rc   r   r  r  Zscore_namesnamer  ri  r[   r[   r\   *test_callable_multimetric_confusion_matrix.  s    


rn  c                  C   s   dd } t dddd\}}tdd}t|dd	d
gi| dd}t|dd	d
giddgdd}||| ||| |jt|jksJ |j|jksJ |||t|||ksJ d S )Nc                 S   s    |  |}t||t||dS )N)r   r   )rj   r%   r    r  rc   r   r  r[   r[   r\   rj  G  s    
zHtest_callable_multimetric_same_as_list_of_strings.<locals>.custom_scorerrk  r   r7  r	  r   r   r   rn   r   r5  r   	r   rC   r(   re   r'  r   r  r   rq   )rj  rc   r   r  search_callable
search_strr[   r[   r\   1test_callable_multimetric_same_as_list_of_stringsE  s    
rs  c                  C   s*  dd } t dddd\}}tdd}t|dd	d
gi| dd}t|dd	d
giddd}t|dd	d
gidgdd}||| ||| ||| |jt|jksJ |j|jksJ |||t|||ksJ |jt|jksJ |j|jksJ |||t|||ks&J d S )Nc                 S   s   |  |}t||S rW   )rj   r%   ro  r[   r[   r\   rj  a  s    
zHtest_callable_single_metric_same_as_single_string.<locals>.custom_scorerrk  r   r7  r	  r   r   r   rn   Tr5  r   rp  )rj  rc   r   r  rq  rr  Zsearch_list_strr[   r[   r\   1test_callable_single_metric_same_as_single_string_  s&    
"rt  c                  C   sz   dd } t dddd\}}ttdddd	d
gi| dd}d}tjt|d ||| W d    n1 sl0    Y  d S )Nc                 S   s   ddiS )NZbad_namern   r[   r  rc   r   r[   r[   r\   
bad_scorer}  s    zBtest_callable_multimetric_error_on_invalid_key.<locals>.bad_scorerrk  r   r7  r	  r   r   r   rn   Z	good_namer5  z`For multi-metric scoring, the parameter refit must be set to a scorer key or a callable to refitr   )r   r(   rC   r   r   r   re   )rv  rc   r   r   r`  r[   r[   r\   .test_callable_multimetric_error_on_invalid_key{  s    
rw  c                  C   s   dd } t dddd\}}t }t|dg dig| d	d
d}tjdtjd}tjt|d |	|| W d    n1 s|0    Y  t
|jd g d d S )Nc                 S   s   ddiS Nr   rn   r[   ru  r[   r[   r\   rj    s    zBtest_callable_multimetric_error_failing_clf.<locals>.custom_scorerr,  r   r   r	  r0  r  Fr   r  zm5 fits failed.+total of 15.+The score on these train-test partitions for these parameters will be set to 0\.1r  r   Zmean_test_acc)rn   rn   r   )r   r	  r(   r  r  r  r   r  r   re   rP   r   )rj  rc   r   r   r   r  r[   r[   r\   +test_callable_multimetric_error_failing_clf  s"    *ry  c                  C   s   dd } t dddd\}}t }t|dtjgd ig| d	d
d}d}tjd| tjd}tjt	|d |
|| W d    n1 s0    Y  d S )Nc                 S   s   ddiS rx  r[   ru  r[   r[   r\   rj    s    zBtest_callable_multimetric_clf_all_fits_fail.<locals>.custom_scorerr,  r   r   r	  r0  r   Fr   r  z1ValueError: Failing classifier failed as requiredz5All the 15 fits failed.+your model is misconfigured.+r  r   r  )rj  rc   r   r   r   Zindividual_fit_error_messager   r[   r[   r\   +test_callable_multimetric_clf_all_fits_fail  s&    rz  c                  C   s   d} t | d\}}t }dddgi}t||}t||dd}t|drJJ t|drXJ ||| ||| |j| ks~J |j| ksJ d S )Nr   r
  Zmax_iterr   rn   r   n_features_in_)r   r   r(   r1   r   re   r|  )r
  rc   r   Zgbdtr   r   r  r[   r[   r\   test_n_features_in  s    
r}  pairwisec                    sJ   G  fdddt }| }d}t|ddgi} | jjksFJ |dS )z
    Test implementation of BaseSearchCV has the pairwise tag
    which matches the pairwise tag of its estimator.
    This test make sure pairwise tag is delegated to the base estimator.

    Non-regression test for issue #13920.
    c                       s   e Zd Z fddZ  ZS )zStest_search_cv_pairwise_property_delegated_to_base_estimator.<locals>.TestEstimatorc                    s   t   }|j_|S rW   )r;  __sklearn_tags__
input_tagsr~  rZ   tags)r  r~  r[   r\   r    s    
zdtest_search_cv_pairwise_property_delegated_to_base_estimator.<locals>.TestEstimator.__sklearn_tags__)rw   rx   ry   r  rC  r[   r~  r>  r\   TestEstimator  s   r  z.BaseSearchCV pairwise tag must match estimatorr  r   N)r   r(   r  r  r~  )r~  r  r  attr_messager   r[   r  r\   <test_search_cv_pairwise_property_delegated_to_base_estimator  s
    
r  c                  C   s\   G dd dt } |  }d}dD ]8}|j|d t|ddgi}|| jjksJ |qdS )	z
    Test implementation of BaseSearchCV has the pairwise property
    which matches the pairwise tag of its estimator.
    This test make sure pairwise tag is delegated to the base estimator.

    Non-regression test for issue #13920.
    c                       s&   e Zd ZdddZ fddZ  ZS )zXtest_search_cv__pairwise_property_delegated_to_base_estimator.<locals>.EstimatorPairwiseTc                 S   s
   || _ d S rW   r  )rZ   r~  r[   r[   r\   r]     s    zatest_search_cv__pairwise_property_delegated_to_base_estimator.<locals>.EstimatorPairwise.__init__c                    s   t   }| j|j_|S rW   )r;  r  r~  r  r  r>  r[   r\   r    s    

zitest_search_cv__pairwise_property_delegated_to_base_estimator.<locals>.EstimatorPairwise.__sklearn_tags__)T)rw   rx   ry   r]   r  rC  r[   r[   r>  r\   EstimatorPairwise  s   
r  z4BaseSearchCV _pairwise property must match estimatorr  r  r  r   N)r   rv   r(   r  r  r~  )r  r  r  Z_pairwise_settingr   r[   r[   r\   =test_search_cv__pairwise_property_delegated_to_base_estimator  s    		r  c                  C   s   d} d}t | dd\}}ddgi}t }t|||d}||| ||}t|}tdd	}t|||d}||| ||}	d
}
||	k sJ |
dS )z
    Test implementation of BaseSearchCV has the pairwise tag
    which matches the pairwise tag of its estimator.
    This test ensures the equivalence of 'precomputed'.

    Non-regression test for issue #13920.
    rd  r   r   re  r  r   r   r$  )Zmetricz2GridSearchCV not identical with precomputed metricN)r   r:   r(   re   rj   r'   r  )r   r   rc   r   grid_paramsr   r   Zpreds_originalZX_precomputedZpreds_precomputedr  r[   r[   r\   ;test_search_cv_pairwise_property_equivalence_of_precomputed	  s    



r  zSearchCV, param_searchr  r   r9  r   c                 C   sP   G dd dt t}| | |}tdd\}}|j||dd |jjdksLJ d S )Nc                   @   s(   e Zd ZdddZd	ddZdd ZdS )
z,test_scalar_fit_param.<locals>.TestEstimatorNc                 S   s
   || _ d S rW   )r  )rZ   r  r[   r[   r\   r]   5	  s    z5test_scalar_fit_param.<locals>.TestEstimator.__init__c                 S   s
   || _ d S rW   )r_)rZ   rc   r   rr[   r[   r\   re   8	  s    z0test_scalar_fit_param.<locals>.TestEstimator.fitc                 S   s   t jt|dS )Nrg   )r_   r   r^   rk   r[   r[   r\   rj   ;	  s    z4test_scalar_fit_param.<locals>.TestEstimator.predict)N)N)rw   rx   ry   r]   re   rj   r[   r[   r[   r\   r  4	  s   

r  r7  r   )r  )r   r   r   re   r   r  )r   param_searchr  modelrc   r   r[   r[   r\   test_scalar_fit_param,	  s
    
r  r   c           
      C   sh   t tddddi\}}}}G dd dt}dd }| | |}||f|dd}	|j||fi |	 d S )	Nr7  r   r   c                       s   e Zd Zd fdd	Z  ZS )z9test_scalar_fit_param_compat.<locals>._FitParamClassifierNc                    s`   t  j|||d |dksJ t|s*J t|ts8J |d jdksJJ |d jdks\J | S )N)sample_weightr   r   rn   )r;  re   callabler   r   ndim)rZ   rc   r   r  tuple_of_arraysscalar_paramcallable_paramr>  r[   r\   re   W	  s    	z=test_scalar_fit_param_compat.<locals>._FitParamClassifier.fit)NNNN)rw   rx   ry   re   rC  r[   r[   r>  r\   _FitParamClassifierV	  s
       r  c                   S   s   d S rW   r[   r[   r[   r[   r\   _fit_param_callablej	  s    z9test_scalar_fit_param_compat.<locals>._fit_param_callable)r  r  r  )r4   r   r   re   )
r   r  ZX_trainZX_validr*  Zy_validr  r  r  rI  r[   r[   r\   test_scalar_fit_param_compatD	  s    r  z)ignore:The total space of parameters 4 is	Predictorc           	      C   s   t jd}|ddt dgd dgd   }}tdt fd| fg}dd	gdd	gd
}| ||dd}||| |j	 |	 ksJ |
|}t|rt|d |||tt||ksJ n.t||  |||tt||ksJ d S )Nr      r   r   rn   r,  ZtransformerZ	predictorr   )Ztransformer__paramZpredictor__paramar   r  )r_   r   r   Zrandnr   r<   rN   re   r   r;  rj   r   rS   rq   r   r  r    rP   r  r$   )	r   r  r   rc   r   r  ru   r  r  r[   r[   r\   1test_search_cv_using_minimal_compatible_estimator~	  s"    (

"r  c                 C   s   t ddddd\}}tdd}ddgi}t||d	d
d
|d|| |  j}|r`td|}ntd|}t|d
ks|J dS )zkCheck that search cv with verbose>2 shows the score for single
    metrics. non-regression test for #19658.r   r   r   r   r   r   r   r   r   r   )r   r   r   r  z$score=\(train=[\d\.]+, test=[\d.]+\)zscore=[\d\.]+N)	r   rC   r(   re   Z
readouterroutr  findallr^   )Zcapsysr  rc   r   r   r   Zcapturedr   r[   r[   r\   test_search_cv_verbose_3	  s$    


r  rw  c           	      C   s   t dd\}}t gdgd}|d d j}tdt fdg}||i}| |fd	d
dd|||}|d d j|ks|J |jjd jdksJ d S )Nr7  r   r9  )r   Zclf__Cr   r   Ztrs)r   NTr   r   r   r   r   )r   rC   r   r<   rN   re   r   Znamed_steps)	r   r  rc   r   ru   Zorig_Cr   param_grid_searchr   r[   r[   r\   test_search_estimator_param	  s    
r  c               	   C   s   ddd} t dt fdt fg}t|| dddd	dd
}g d}g d}||| |jd }tjdtd}g d|d d < tj	
|j| d S )N)rc  rn   r   )l1l2)Zvect__ngram_rangeZ
vect__normZvectr   r   r   r   rn   )rq  rw  r   r   rQ  r   r   )oner$  threefourfive)r   r   rn   r   rn   Zparam_vect__ngram_ranger  )r  r  rc  )r<   r   r8   r1   re   r   r_   r   objectr  rS   r   )Zparameter_gridpipeliner   Z
data_trainZdata_targetresultZexpected_datar[   r[   r\   test_search_with_2d_array	  s0    	
r  c                  C   s:  t dd\} }tdt fdt fg}dt t gi}t||dd}tdd$ | }d	|v sdJ W d
   n1 sx0    Y  || | tdd$ | }d	|v sJ W d
   n1 s0    Y  t||dd}|| | tdd4 | }d	|vsJ d|v sJ W d
   n1 s,0    Y  d
S )z5Test different HTML representations for GridSearchCV.r7  r   r  r   F)r   r   Zdiagram)displayz<pre>DummyClassifier()</pre>NTz<pre>LogisticRegression()</pre>)	r   r<   rA   r   r   r(   r   Z_repr_html_re   )rc   r   r  r   rE  Z	repr_htmlr[   r[   r\   test_search_html_repr	  s"    **r  c                 C   s"  t  }| |dg diddd}|ttt}tjtdd |  W d    n1 s\0    Y  tjtdd |j||d	 W d    n1 s0    Y  t	j
d
d$ t	d || W d    n1 s0    Y  tjtdd |j|d W d    n1 s0    Y  d S )NrY   r   r   r   r   z$Missing required positional argumentr   z$Cannot use both X and Xt. Use X only)rc   XtT)recorderrorzXt was renamed X in version 1.5)r  )rV   re   rc   r   rl   r   r   r   rm   warningscatch_warningssimplefilterr  FutureWarning)r   r   r  ZX2r[   r[   r\   %test_inverse_transform_Xt_deprecation
  s    &,
(r  )Zenable_metadata_routingc              	   C   s   t dd\}}t|}tjd}||}||}t }|ddgii}	t }
t|
dj	ddd	}t
|d
d}| |fd
d|d|	j||||d t|
sJ |
D ]}t|ddd	||d qdS )zMTest that *SearchCV forwards metadata correctly when passed multiple metrics.r7  r   r   r   rn   )registryscore_weightsscore_metadata)r  metadatar   )Z	my_scorerr   r   r  )r  r  rq   Z_score)objr  parentZsplit_paramsr  r  N)r   rU   r_   r   r   ZrandrC   rE   rD   Zset_score_requestrl  re   r^   rF   )r   r  rc   r   r   r   r  r  r  r  Zscorer_registryZscorerr   Z_scorerr[   r[   r\   *test_multi_metric_search_forwards_metadata$
  s2    



r  c                 C   s   t dd\}}t }|ddgii}| |fddi|||}tjtdd  |j||dd	 W d
   n1 sr0    Y  d
S )z{*SearchCV should reject **params when metadata routing is not enabled
    since this is added only when routing is enabled.r7  r   r   rn   r   r   zis only supported ifr   )r  N)r   rC   re   r   r   r   rq   )r   r  rc   r   r  r  r   r[   r[   r\   1test_score_rejects_params_with_no_routing_enabledK
  s    r  c                  C   s   G dd dt t} dddiddigdddggd	digd
dgd}t| t |dd}tdd\}}||| |D ]}|jd|  jtksrJ qrdS )zQNon-regression test for https://github.com/scikit-learn/scikit-learn/issues/29074c                   @   s(   e Zd ZdddZd	ddZdd ZdS )
z8test_cv_results_dtype_issue_29074.<locals>.MetaEstimatorNc                 S   s"   || _ || _|| _|| _|| _d S rW   )base_clf
parameter1
parameter2
parameter3
parameter4)rZ   r  r  r  r  r  r[   r[   r\   r]   h
  s
    zAtest_cv_results_dtype_issue_29074.<locals>.MetaEstimator.__init__c                 S   s   | j || | S rW   )r  re   r3  r[   r[   r\   re   v
  s    z<test_cv_results_dtype_issue_29074.<locals>.MetaEstimator.fitc                 S   s   | j ||S rW   )r  rq   r3  r[   r[   r\   rq   z
  s    z>test_cv_results_dtype_issue_29074.<locals>.MetaEstimator.score)NNNN)N)rw   rx   ry   r]   re   rq   r[   r[   r[   r\   MetaEstimatorg
  s       

r  NoptionABrn   r   r  Zstr1Zstr2)r  r  r  r  r   r-  r   r   Zparam_)	r   r   r(   r   r   re   r   r  r  )r  r   r   rc   r   r  r[   r[   r\   !test_cv_results_dtype_issue_29074d
  s    
r  c                  C   s   t d} | g dg dg dd}|jddd}|d }td	td
ddgfgdd}td	|fdt fg}dtd
dt gi}t	||dd}|
|| |jd jtksJ dS )zNCheck cv_results_ for estimators with a `dtype` parameter, e.g. OneHotEncoder.r_  )rn   r   r   r   r   )r  r  r  r  r  )ro   gffffff@r   g      @ro   )Z	numeric_1object_1targetr  rn   r  encF)Zsparse_outputr  Zpassthrough)	remainderr   Zenc__encr   r   Zparam_enc__encN)r   ZimportorskiprX  Zdropr   r>   r<   r   r?   r(   re   r   r  r  )pdZdfrc   r   r  r   r  r   r[   r[   r\   'test_search_with_estimators_issue_29157
  s4    
r  c                     s|   d t dd\} }ttddt } fdddD } fdd|D }t|d	|id
}|| | |jd jtksxJ dS )zwCheck that GridSearchCV works with params that are arrays of different sizes.

    Non-regression test for #29277.
    r   r{  Zperiodic)Zextrapolationc                    s   g | ]} | qS r[   r[   r   r{  r[   r\   r   
  r   z4test_cv_results_multi_size_array.<locals>.<listcomp>)r   rL     c                    s*   g | ]"}t d t jd |d fqS )r   r   r   )r_   Zlinspacepir   )r   Zn_knotsr{  r[   r\   r   
  s   Zsplinetransformer__knotsr  Zparam_splinetransformer__knotsN)	r   r=   r@   r   r(   re   r   r  r  )rc   r   Zspline_reg_pipeZn_knots_listZ
knots_listZspline_reg_pipe_cvr[   r{  r\    test_cv_results_multi_size_array
  s$    
r  zarray_namespace, device, dtypec                 C   s   t ||}tdd}||}|j||d}tdgd dgd  }|j||d}	tddB | t d	g d
iddd}
|
	||	 |

||	 W d    n1 s0    Y  d S )Nr   )r   r   )devicer   r   rn   T)Zarray_api_dispatchZtol)r9  r  g-C6?gh㈵>gư>gHz>r   r   r   )rO   r_   r   r   ZastypeZasarrayr   r   r   re   rq   )r   Zarray_namespacer  r  Zxprc   ZX_npZX_xpZy_npZy_xpr   r[   r[   r\   #test_array_api_search_cv_classifier
  s    


r  )r  r  r  )r   r   )candidate_paramsexpectedZ	param_foozsimple numeric, single param)idr   r   Z	param_bar)r   r   r   )FFTr  z1simple numeric, one param is missing in one roundr  zlists of different lengthszlists tuplesr  c                 C   sh   t t| }t||D ]L\\}}\}}||ks2J |j|jksBJ tj|| tj|j|j qd S rW   )r   r6   r]  r  r_   r  rS   r  )r  r  r  r>  r   Zexpected_keyZexpected_valuer[   r[   r\   &test_yield_masked_array_for_each_param
  s    6r  c                  C   sV   dd t dD } t ( tdt tt|  W d    n1 sH0    Y  d S )Nc                 S   s   g | ]}d |iqS )r  r[   r   r[   r[   r\   r   7  r   z>test_yield_masked_array_no_runtime_warning.<locals>.<listcomp>r&  r  )r   r  r  r  RuntimeWarningr   r6   )r  r[   r[   r\   *test_yield_masked_array_no_runtime_warning5  s    
r  )r[   )rz   r  r  r   r  collections.abcr   r   	functoolsr   ior   	itertoolsr   r   rb  r   numpyr_   r   Zscipy.statsr	   r
   r   r   r   Zsklearn.baser   r   r   Zsklearn.clusterr   Zsklearn.composer   Zsklearn.datasetsr   r   r   Zsklearn.discriminant_analysisr   Zsklearn.dummyr   Zsklearn.ensembler   Zsklearn.exceptionsr   Zsklearn.experimentalr   Zsklearn.feature_extraction.textr   Zsklearn.imputer   Zsklearn.linear_modelr   r   r   r   Zsklearn.metricsr    r!   r"   r#   r$   r%   r&   Zsklearn.metrics.pairwiser'   Zsklearn.model_selectionr(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   Zsklearn.model_selection._searchr5   r6   Z$sklearn.model_selection.tests.commonr7   Zsklearn.naive_bayesr8   Zsklearn.neighborsr9   r:   r;   Zsklearn.pipeliner<   r=   Zsklearn.preprocessingr>   r?   r@   rA   Zsklearn.svmrB   rC   Z%sklearn.tests.metadata_routing_commonrD   rE   rF   Zsklearn.treerG   rH   Zsklearn.utils._array_apirI   Zsklearn.utils._mockingrJ   rK   Zsklearn.utils._testingrL   rM   rN   rO   rP   rQ   rR   rS   Zsklearn.utils.fixesrT   Zsklearn.utils.validationrU   rV   r~   r   rc   r   r   markZparametrizer   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r   r#  r+  r-  r.  filterwarningsr6  r@  rC  rH  rI  rQ  rV  rW  rc  rn  ru  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r	  r  r  r  r)  r.  r/  r3  r4  rH  rM  rT  rY  ra  rn  rs  rt  rw  ry  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  Zone_hot_encoderZordinal_encoderr  r  r   r  Zma_with_tuplesr  r  r  r[   r[   r[   r\   <module>   s:  $	<(
'"$
+
	(

$

-ZE
8#$&




!"

(%.	Q( 	_	9
-
 

3




-!

""(

5	