
    -i                        S r SSKrSSKrSSKJr  SSKJr  SSKJ	r	J
r
Jr  SSKJr  SS/SS/SS/S	S	/S	S
/S
S	//r/ SQrSS/S
S
/SS
//r/ SQr/ SQr/ SQrS	S/SS	/SS	//r\R*                  " 5       r\R.                  R1                  S	5      r\R5                  \R6                  R8                  5      r\R<                  \   \l        \R6                  \   \l        \R>                  RA                  S\5      S 5       r!S r"S r#S r$S r%S r&S r'\R>                  RA                  S\5      S 5       r(S r)S r*S r+\R>                  RA                  S/ SQ5      S  5       r,\R>                  RA                  S!\RZ                  /\-   5      S" 5       r.g)#z*
Testing for the nearest centroid module.
    N)datasets)NearestCentroid)assert_allcloseassert_array_almost_equalassert_array_equal)CSR_CONTAINERS      )r
   r
   r
   r   r   r      )r
   r   r   )i@   P   gj=gHKbi):g68csr_containerc                 N   U " [         5      nU " [        5      n[        5       nUR                  [         [        5        [        UR                  [        5      [        5        [        UR                  [        5      [        5        [        UR                  [        5      [        5        [        SS9nUR                  [         [        5        [        UR                  [        5      [        5        [        UR                  [        5      [        5        [        UR                  [        5      [        5        [        SS9nUR                  [         [        5        [        UR                  [        5      [        5        [        UR                  [        5      [        5        [        UR                  [        5      [        5        [        SS/S9nUR                  [         [        5        [        UR                  [        5      [        5        [        5       nUR                  U[        5        [        UR                  U5      [        5        [        5       nUR                  U[        5        [        UR                  [        5      [        5        [        5       nUR                  [         [        5        [        UR                  U5      [        5        [        5       nUR                  UR                  5       [        5        [        UR                  UR                  5       5      [        5        g )Nuniformpriors	empiricalg      ?g      ?)XTr   fityr   predicttrue_resultr   decision_functiontrue_discriminant_scorespredict_proba
true_probatrue_result_prior1tocootolil)r   X_csrT_csrclfs       `/var/www/html/venv/lib/python3.13/site-packages/sklearn/neighbors/tests/test_nearest_centroid.pytest_classification_toyr'   %   s    !E!E 
CGGAqMs{{1~{3c33A68PQc//2J? 
+CGGAqMs{{1~{3c33A68PQc//2J?

-CGGAqMs{{1~{3c33A68PQc//2J? $
.CGGAqMs{{1~'9: 
CGGE1s{{5);7 
CGGE1s{{1~{3 
CGGAqMs{{5);7 
CGGEKKM1s{{5;;=1;?    c                  :   S H  n [        U S9R                  [        R                  [        R                  5      n[
        R                  " UR                  [        R                  5      [        R                  :H  5      nUS:  a  M   S[        U5      -   5       e   g )N	euclidean	manhattanmetricg?Failed with score = 	r   r   irisdatatargetnpmeanr   str)r.   r%   scores      r&   	test_irisr8   Y   sj    ,V,00DKKHDII.$++=>s{?2SZ??{ -r(   c                  P   S H  n S H  n[        XS9nUR                  [        R                  [        R                  5      n[
        R                  " UR                  [        R                  5      [        R                  :H  5      nUS:  a  M   S[        U5      -   5       e   M     g )Nr*   )N皙?g      ?)r.   shrink_thresholdg?r/   r0   )r.   r;   r%   r7   s       r&   test_iris_shrinkager<   a   sx    , 0!SC''$))T[[1CGGCKK		2dkkABE3;C 6U CC;	 !1 -r(   c                     SS K n [        5       nUR                  [        R                  [        R
                  5        UR                  [        R                  [        R
                  5      nU R                  U5      nU R                  U5      n[        U5      UR                  :X  d   eUR                  [        R                  [        R
                  5      n[        UUS5        g )Nr   z>Failed to generate same score after pickling (classification).)pickler   r   r1   r2   r3   r7   dumpsloadstype	__class__r   )r>   objr7   sobj2score2s         r&   test_picklerG   k   s     
CGGDIIt{{#IIdii-ESA<<?D:&&&ZZ		4;;/FHr(   c                  >   [         R                  " SS/SS/SS/SS/SS//5      n [         R                  " / SQ5      n[        SS9nUR                  X5        [         R                  " S	S
/SS//5      n[         R                  R                  UR                  U5        g )Nr   r   r         )r   r   r   r   r   r:   r;   g;4,F]?gCMX?gJGp@gU@)r4   arrayr   r   testingr   
centroids_)r   r   r%   expected_results       r&   test_shrinkage_correctrP   ~   s     	1a&1a&1a&1a&1a&9:A
!A
3
/CGGAMhhI 688LMNOJJ((Ir(   c                      [        SS9n [        R                  " [        5      nSXS:H  '   U R	                  [
        U5        U R                  nU R	                  [
        [        5        [        X R                  5        g )Ng{Gz?rK   r   r
   )r   r4   asarrayr   r   r   rN   r   )r%   y_indcentroid_encodeds      r&   "test_shrinkage_threshold_decoded_yrU      sW    
4
0CJJqMEE2+GGAu~~GGAqM'8r(   c                  x   [         R                  R                  S5      n U R                  SS5      nU R	                  SSS5      nU R                  S5      n[        SS9nUR                  X5        UR                  U5      n[        SS9nX-   nUR                  Xb5        UR                  U5      n[        XW5        g )Nr   2   r   r:   rK   )	r4   randomRandomStaterandrandintr   r   r   r   )rngr   r   noiser%   y_initX_noisey_translates           r&   test_predict_translated_datara      s     ))


"CRAAq"AHHRLE
3
/CGGAM[[^F
3
/CiGGGG++g&Kv+r(   c                     U " [         5      n[        SS9nUR                  [         [        5        UR                  nUR                  U[        5        [        UR                  U5        [        USS/SS//5        g )Nr,   r-   r
   r   )r   r   r   r   rN   r   )r   r#   r%   dense_centroids       r&   test_manhattan_metricrd      sa     !E

-CGGAqM^^NGGE1s~~~6~R1a&'9:r(   c                  &   [         R                  " S5      n SU S S 2S4'   SU S S 2S4'   [         R                  " S5      nSUS'   [        SS9n[        R
                  " [        5         UR                  X5        S S S 5        g ! , (       d  f       g = f)	N)
   r   g$b@r   g_LOчr   rf   r:   rK   )r4   emptyzerosr   pytestraises
ValueErrorr   )r   r   r%   s      r&   test_features_zero_varrl      so     	AAadGAadG
"AAaD
3
/C	z	" 
#	"	"s   'B
Bc                      [        SS/S9n [        R                  " [        SS9   U R	                  [
        [        5        SSS5        g! , (       d  f       g= f)zGCheck that we raise an error when the user-defined priors are negative.r	      r   zpriors must be non-negativematchN)r   ri   rj   rk   r   r   r   )r%   s    r&   test_negative_priors_errorrq      s9    
"a
)C	z)F	G1 
H	G	Gs   A		
Ac                  V   SS/n [        U S9n[        R                  " [        SS9   UR	                  [
        [        5        SSS5        [        UR                  [        R                  " U 5      [        R                  " U 5      R                  5       -  5        g! , (       d  f       N^= f)z^Check that we raise a warning and normalize the user-defined priors when they
don't sum to 1.
r   rn   r   zAThe priors do not sum to 1. Normalizing such that it sums to one.ro   N)r   ri   warnsUserWarningr   r   r   r   class_prior_r4   rR   sum)r   r%   s     r&   test_warn_non_normalized_priorsrw      sz     VF

(C	Q
 	1	
 C$$bjj&82::f;M;Q;Q;S&ST
 
s   B
B(response_method)r   r   predict_log_probac                     [        SS9R                  [        [        5      n[        R
                  " [        5         [        X5      " [        5        SSS5        g! , (       d  f       g= f)zsCheck that we raise an AttributeError with Manhattan metric when trying
to call a non-thresholded response method.
r,   r-   N)	r   r   r   r   ri   rj   AttributeErrorgetattrr   )rx   r%   s     r&   (test_method_not_available_with_manhattanr}      s@     
-
1
1!Q
7C	~	&%a( 
'	&	&s   A
A)array_constructorc                 &   [         R                  " [        [        5      S45      nUSS2S4==   S-  ss'   U " U5      n[	        5       n[
        R                  " [        SS9   UR                  U[        5        SSS5        g! , (       d  f       g= f)zHCheck that we raise an error when the variance for all features is zero.r   Nr   zAll features have zero variancero   )	r4   oneslenr   r   ri   rj   rk   r   )r~   r   r%   s      r&   test_error_zero_variancesr      sf     	QAadGqLG!A

C	z)J	K1 
L	K	Ks   "B
B)/__doc__numpyr4   ri   sklearnr   sklearn.neighborsr   sklearn.utils._testingr   r   r   sklearn.utils.fixesr   r   r   r   r   r    r   r   	load_irisr1   rX   rY   r\   permutationr3   sizepermr2   markparametrizer'   r8   r<   rG   rP   rU   ra   rd   rl   rq   rw   r}   rL   r    r(   r&   <module>r      s      - 
 / 	"XBx"bAq6Aq6Aq6:"X1v1v ( +a 0;2BC

 iiA
t{{''(IIdO	kk$ .90@ :0@f@D&J9," .9	; :	;U R)) ,rxxj>.IJ Kr(   