o
    Ó\i”  ã                   @   sª  d Z ddlZddl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gddgddgd	d	gd	d
gd
d	ggZg d¢Zddgd
d
gdd
ggZg d¢Zg d¢Zg d¢Zd	dgdd	gdd	ggZe ¡ Zej d	¡Ze ejj¡Zeje e_eje e_ej  de¡dd„ ƒZ!dd„ Z"dd„ Z#dd„ Z$dd„ Z%dd„ Z&dd „ Z'ej  de¡d!d"„ ƒZ(d#d$„ Z)d%d&„ Z*d'd(„ Z+ej  d)g d*¢¡d+d,„ ƒZ,ej  d-ej-ge ¡d.d/„ ƒZ.dS )0z*
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„=gHKb†Ói):gÍ6·–ý·8Úcsr_containerc                 C   sœ  | t ƒ}| tƒ}tƒ }| t t¡ t| t¡tƒ t| 	t¡t
ƒ t| t¡tƒ tdd}| t t¡ t| t¡tƒ t| 	t¡t
ƒ t| t¡tƒ tdd}| t t¡ t| t¡tƒ t| 	t¡t
ƒ t| t¡tƒ tddgd}| t t¡ t| t¡tƒ tƒ }| |t¡ t| |¡tƒ tƒ }| |t¡ t| t¡tƒ tƒ }| t t¡ t| |¡tƒ tƒ }| | ¡ t¡ t| | ¡ ¡tƒ d S )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Úclf© r$   úŽ/var/www/www-root/data/www/176.119.141.140/sports-predictor/venv/lib/python3.10/site-packages/sklearn/neighbors/tests/test_nearest_centroid.pyÚtest_classification_toy%   s@   

r&   c                  C   sT   dD ]%} t | d tjtj¡}t | tj¡tjk¡}|dks'J dt|ƒ ƒ‚qd S )N©Ú	euclideanÚ	manhattan©ÚmetricgÍÌÌÌÌÌì?úFailed with score = ©	r   r   ÚirisÚdataÚtargetÚnpÚmeanr   Ústr)r+   r#   Úscorer$   r$   r%   Ú	test_irisY   s
   ýr5   c                  C   sd   dD ]-} dD ](}t | |d}| tjtj¡}t | tj¡tjk¡}|dks.J dt|ƒ ƒ‚qqd S )Nr'   )Nçš™™™™™¹?g      à?)r+   Úshrink_thresholdgš™™™™™é?r,   r-   )r+   r7   r#   r4   r$   r$   r%   Útest_iris_shrinkagea   s   üÿr8   c                  C   st   dd l } tƒ }| tjtj¡ | tjtj¡}|  |¡}|  |¡}t	|ƒ|j
ks*J ‚| tjtj¡}t||dƒ d S )Nr   z>Failed to generate same score after pickling (classification).)Úpickler   r   r.   r/   r0   r4   ÚdumpsÚloadsÚtypeÚ	__class__r   )r9   Úobjr4   ÚsÚobj2Úscore2r$   r$   r%   Útest_picklek   s   

ýrB   c                  C   sv   t  ddgddgddgddgddgg¡} t  g d¢¡}tdd}| | |¡ t  d	d
gddgg¡}t j |j|¡ d S )Nr   r
   r   é   é   )r
   r
   r   r   r   r6   ©r7   g;4,F]ëè?gðCïžMXë?gJ¸Gpƒ@g‚Uõò@)r1   Úarrayr   r   Útestingr   Ú
centroids_)r   r   r#   Úexpected_resultr$   r$   r%   Útest_shrinkage_correct~   s   (
rJ   c                  C   sN   t dd} t t¡}d||dk< |  t|¡ | j}|  tt¡ t|| jƒ d S )Ng{®Gáz„?rE   r   r	   )r   r1   Úasarrayr   r   r   rH   r   )r#   Úy_indÚcentroid_encodedr$   r$   r%   Ú"test_shrinkage_threshold_decoded_yŒ   s   

rN   c                  C   s†   t j d¡} |  dd¡}|  ddd¡}|  d¡}tdd}| ||¡ | |¡}tdd}|| }| ||¡ | |¡}t||ƒ d S )Nr   é2   r   r6   rE   )	r1   ÚrandomÚRandomStateÚrandÚrandintr   r   r   r   )Úrngr   r   Únoiser#   Úy_initÚX_noiseÚy_translater$   r$   r%   Útest_predict_translated_data–   s   




rY   c                 C   sV   | t ƒ}tdd}| t t¡ |j}| |t¡ t|j|ƒ t|ddgddggƒ d S )Nr)   r*   r	   r
   )r   r   r   r   rH   r   )r   r!   r#   Údense_centroidr$   r$   r%   Útest_manhattan_metric§   s   
r[   c                  C   s‚   t  d¡} d| d d …df< d| d d …df< t  d¡}d|d< tdd}t t¡ | | |¡ W d   ƒ d S 1 s:w   Y  d S )	N)é
   r   g$bŒ@£‘Á¿r   g_LéOÑ‡ï¿r
   r\   r6   rE   )r1   ÚemptyÚzerosr   ÚpytestÚraisesÚ
ValueErrorr   )r   r   r#   r$   r$   r%   Útest_features_zero_var´   s   


"ÿrb   c                  C   sN   t ddgd} tjtdd |  tt¡ W d  ƒ dS 1 s w   Y  dS )zGCheck that we raise an error when the user-defined priors are negative.r   é   r   zpriors must be non-negative©ÚmatchN)r   r_   r`   ra   r   r   r   )r#   r$   r$   r%   Útest_negative_priors_errorÂ   s   "ÿrf   c                  C   sp   ddg} t | d}tjtdd | tt¡ W d  ƒ n1 s!w   Y  t|jt	 
| ¡t	 
| ¡ ¡  ƒ dS )zfCheck that we raise a warning and normalize the user-defined priors when they
    don't sum to 1.
    r   rc   r   zAThe priors do not sum to 1. Normalizing such that it sums to one.rd   N)r   r_   ÚwarnsÚUserWarningr   r   r   r   Úclass_prior_r1   rK   Úsum)r   r#   r$   r$   r%   Útest_warn_non_normalized_priorsÉ   s   
þü$rk   Úresponse_method)r   r   Úpredict_log_probac                 C   sP   t dd tt¡}t t¡ t|| ƒtƒ W d  ƒ dS 1 s!w   Y  dS )z{Check that we raise an AttributeError with Manhattan metric when trying
    to call a non-thresholded response method.
    r)   r*   N)	r   r   r   r   r_   r`   ÚAttributeErrorÚgetattrr   )rl   r#   r$   r$   r%   Ú(test_method_not_available_with_manhattanØ   s   "ÿrp   Úarray_constructorc                 C   sx   t  ttƒdf¡}|dd…df  d9  < | |ƒ}tƒ }tjtdd | |t¡ W d  ƒ dS 1 s5w   Y  dS )zHCheck that we raise an error when the variance for all features is zero.r   Nr
   zAll features have zero variancerd   )	r1   ÚonesÚlenr   r   r_   r`   ra   r   )rq   r   r#   r$   r$   r%   Útest_error_zero_variancesä   s   "ÿrt   )/Ú__doc__Únumpyr1   r_   Úsklearnr   Úsklearn.neighborsr   Úsklearn.utils._testingr   r   r   Úsklearn.utils.fixesr   r   r   r   r   r   r   r   Ú	load_irisr.   rP   rQ   rT   Úpermutationr0   ÚsizeÚpermr/   ÚmarkÚparametrizer&   r5   r8   rB   rJ   rN   rY   r[   rb   rf   rk   rp   rF   rt   r$   r$   r$   r%   Ú<module>   sL    (
3


ÿ
	