U
    Ovf
                     @   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   N/tmp/pip-unpacked-wheel-qu3nn_q2/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np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    
r4   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    
r9   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)r:   r	   l2N)r   r   r   r   r)   r*   r   r1   )r2   r3   Zclf_l1Zclf_elasticnetZclf_l2r   r   r   test_perceptron_l1_ratioG   s    r=   )!Znumpyr   r5   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-   r4   r9   r=   r   r   r   r   <module>   s&   



