
\Ic           @   s  y d  d l  Z  Wn- e k
 r? d  d l m Z e d   n Xd  d l Z d  d l Z d  d l m Z d d g d d g d	 d
 g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d d g d  d! g d" d# g d$ d% g g Z d& d& d& d& d& d& d& d& d& d& d' d' d' d' d' d' d' g Z d( e j	 f d)     YZ
 e d* k re j d+ d,  Z e j d- e  n  d S(.   iN(   t   MissingExternalDependencyErrors8   Install NumPy if you want to use Bio.LogisticRegression.(   t   LogisticRegressionig)\iiu   g
ףp=pi9   gףp=
odi   ggi   gGzkiU   gGz>hgQfi   gQfig(\fi:   gR=pi~   gGzyi   g
ףp=2oiq   gGzpi   gp=
׏si   g(\ji   gwi]   gGz2ri   i    t   TestLogisticRegressionc           B   s5   e  Z d    Z d   Z d   Z d   Z d   Z RS(   c         C   sd   t  j t t  } | j } |  j | d d d  |  j | d d d  |  j | d d d  d  S(   Ni    gK!@i   i   g;Oni   g46<R?(   R   t   traint   xst   yst   betat   assertAlmostEqual(   t   selft   modelR   (    (    s   test_LogisticRegression.pyt   test_calculate_model;   s
    	c         C   sf   t  j t t  } t  j | d d g  } |  j | d  t  j | d d g  } |  j | d  d  S(   Ni   gqVjei   i5  g>
pi    (   R   R   R   R   t   classifyt   assertEqual(   R   R	   t   result(    (    s   test_LogisticRegression.pyt   test_classifyB   s
    c         C   s   t  j t t  } t  j | d d g  \ } } |  j | d d  |  j | d d  t  j | d d g  \ } } |  j | d d  |  j | d d  d  S(	   Ni   gqVjego`r?g)F{?i5  g>
pg|	5?g|o^?(   R   R   R   R   t	   calculateR   (   R   R	   t   qt   p(    (    s   test_LogisticRegression.pyt   test_calculate_probabilityI   s    c         C   s   d } t  j t t  } d d d d d d d d d d d d d d d d d g } xa t t |   D]M } t  j | t |  } |  j | | |  | t | k rd | d 7} qd qd W|  j | d  d  S(   Ni    i   i   (   R   R   R   R   t   ranget   lenR   R   (   R   t   correctR	   t   predictionst   it
   prediction(    (    s   test_LogisticRegression.pyt   test_model_accuracyR   s    9c         C   s   d } d d d d d d d d d d d d d d d d d g } x t  t |   D] } t j t |  t | d t |  t | d  } t j | t |  } |  j | | |  | t | k rR | d 7} qR qR W|  j | d  d  S(   Ni    i   i   (   R   R   R   R   R   R   R   R   (   R   R   R   R   R	   R   (    (    s   test_LogisticRegression.pyt   test_leave_one_out]   s    92(   t   __name__t
   __module__R
   R   R   R   R   (    (    (    s   test_LogisticRegression.pyR   9   s
   					t   __main__t	   verbosityi   t
   testRunner(   t   numpyt   ImportErrort   BioR    t   unittestt   sysR   R   R   t   TestCaseR   R   t   TextTestRunnert   runnert   main(    (    (    s   test_LogisticRegression.pyt   <module>	   s\   																	/