U
    9%e
                     @   s   d dl Zd dl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mZ e ZedZeejjd  Zee eje Zeje ZeeZe  G dd dZd	d
 Zdd Zdd Zdd Z dS )    N)	load_iris)
Perceptron)check_random_state)assert_allcloseassert_array_almost_equal   c                   @   s.   e Zd ZdddZdd Zdd Zdd	 Zd
S )MyPerceptron   c                 C   s
   || _ d S Nn_iter)selfr    r   i/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sklearn/linear_model/tests/test_perceptron.py__init__   s    zMyPerceptron.__init__c                 C   s   |j \}}tj|tjd| _d| _t| jD ]X}t|D ]J}| || d || kr8|  j|| ||  7  _|  j|| 7  _q8q,d S )N)Zdtypeg        r   )	shapenpZzerosZfloat64wbranger   predict)r   XyZ	n_samplesZ
n_featurestir   r   r   fit   s    
zMyPerceptron.fitc                 C   s   t || j| j S r
   )r   dotr   r   r   r   r   r   r   project#   s    zMyPerceptron.projectc                 C   s   t |}t | |S r
   )r   Z
atleast_2dsignr   r   r   r   r   r   &   s    
zMyPerceptron.predictN)r	   )__name__
__module____qualname__r   r   r   r   r   r   r   r   r      s   
r   c                  C   sD   t tfD ]6} tdd dd}|| t || t}|dkstqd S )Nd   F)max_itertolshufflegffffff?)r   X_csrr   r   r   scoreAssertionError)dataclfr(   r   r   r   test_perceptron_accuracy+   s
    r,   c                  C   sZ   t  } d| t dk< tdd}|t|  tddd d}|t|  t|j|j	  d S )Nr	      r   F)r$   r&   r%   )
r   copyr   r   r   r   r   r   coef_Zravel)Zy_binclf1clf2r   r   r   test_perceptron_correctness3   s    
r3   c               
   C   s8   t dd} dD ]$}tt t| | W 5 Q R X qd S )Nr#   )r$   )Zpredict_probaZpredict_log_proba)r   pytestZraisesAttributeErrorgetattr)r+   methr   r   r   test_undefined_methods@   s    
r8   c                  C   s   t ddd} | tt t ddd}|tt | tt|ttksLtt ddtt}t dddtt}t|j|j t ddtt}t dddtt}t|j|j d	S )
z?Check that `l1_ratio` has an impact when `penalty='elasticnet'`r   Z
elasticnet)Zl1_ratiopenaltyg333333?l1)r9   r	   l2N)r   r   r   r   r(   r)   r   r0   )r1   r2   Zclf_l1Zclf_elasticnetZclf_l2r   r   r   test_perceptron_l1_ratioG   s    r<   )!numpyr   r4   Zscipy.sparsesparsespZsklearn.datasetsr   Zsklearn.linear_modelr   Zsklearn.utilsr   Zsklearn.utils._testingr   r   ZirisZrandom_stateZaranger*   r   indicesr&   r   targetr   Z
csr_matrixr'   Zsort_indicesr   r,   r3   r8   r<   r   r   r   r   <module>   s&   



