o
    tBhx                     @   s   d Z ddlZddlZddlZddlmZm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 g dg d	g d
g dgZg dZdd Zdd Zdd Zdd Zdd Zdd ZdS )zs
Tests for chi2, currently the only feature selection function designed
specifically to work with sparse matrices.
    N)
coo_matrix
csr_matrixSelectKBestchi2)
_chisquare)assert_array_almost_equal)assert_array_equal)      r
   )	   r   r   )   r   r
   )r   r   r
   )r   r   r
   r
   c                 C   s   t t| dS )zMake k-best chi2 selectorkr   r    r   /var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sklearn/feature_selection/tests/test_chi2.pymkchi2   s   r   c                  C   s  t ddtt} t ddtt} t| jdddg t| tttd d dgf  t ddtt} tt	| jddddg t
ttjd}t dd|t} tt	| jddddg | |}t|j|jd dg | }t dd|t }t|| d S )Nr   r   T)indicesr   r
   )dtype)r   fitXyr	   get_support	transformnparraysortedr   float64shapetoarrayfit_transformr   )r   XspXtransXtrans2r   r   r   	test_chi2   s   $
r$   c                  C   s   t t} tdd| t d S )Nr
   r   )r   r   r   r    r   )Xcoor   r   r   test_chi2_coo5   s   r&   c               	   C   sl   ddgddggddg} }| t | t| fD ]} tt t| | W d    n1 s.w   Y  qd S )Nr   r   g#Bǻ)r   r   r   pytestraises
ValueErrorr   )r   r   r   r   r   test_chi2_negative=   s   r*   c                  C   s   t jdd-} t d tddgddggddg\}}| D ]}dt|v r+td| qW d    n1 s6w   Y  t|dtjg t|d tj d S )NT)recordalwaysr   r   zdivide by zerozFound unexpected warning %s)	warningscatch_warningssimplefilterr   reprAssertionErrorr	   r   nan)warnedchipwr   r   r   test_chi2_unused_featureE   s   
r7   c                  C   sd   t ddgddgg} t ddgddgg}tj| |\}}t| |\}}t|| t|| d S )Ng       @g      ?g      ?)r   r   scipystats	chisquarer   r   )obsexpchi_scpp_scpchi_ourp_ourr   r   r   test_chisquareR   s   
rA   )__doc__r-   numpyr   r'   scipy.sparser   r   scipy.statsr8   sklearn.feature_selectionr   r   /sklearn.feature_selection._univariate_selectionr   sklearn.utils._testingr   r	   r   r   r   r$   r&   r*   r7   rA   r   r   r   r   <module>   s$    