o
    iC                     @   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mZ ddlmZmZ g dg dg d	g d
gZg dZdd Zejdedd Zejdedd Zejde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SelectKBestchi2)
_chisquare)assert_array_almost_equalassert_array_equal)COO_CONTAINERSCSR_CONTAINERS)      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   c/home/kim/smarthome/.venv/lib/python3.10/site-packages/sklearn/feature_selection/tests/test_chi2.pymkchi2   s   r   csr_containerc                 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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
   )Zdtype)r   fitXyr   Zget_support	transformnparraysortedZfloat64shapeZtoarrayfit_transformr   )r   r   ZXspZXtransZXtrans2r   r   r   	test_chi2   s   $
r   coo_containerc                 C   s   | t }tdd|t d S )Nr
   r   )r   r   r   r   )r   ZXcoor   r   r   test_chi2_coo5   s   r    c              	   C   sl   ddgddggddg}}|t || |fD ]}tt t|| W d    n1 s.w   Y  qd S )Nr   r   g#Bǻ)r   r   pytestZraises
ValueErrorr   )r   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)Zwarnedchipwr   r   r   test_chi2_unused_featureG   s   
r/   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statsZ	chisquarer   r   )ZobsexpZchi_scpZp_scpZchi_ourZp_ourr   r   r   test_chisquareT   s   
r3   )__doc__r&   numpyr   r!   Zscipy.statsr0   Zsklearn.feature_selectionr   r   Z/sklearn.feature_selection._univariate_selectionr   Zsklearn.utils._testingr   r   Zsklearn.utils.fixesr   r	   r   r   r   markZparametrizer   r    r#   r/   r3   r   r   r   r   <module>   s(    


