
    &h                         d Z ddlZddlmZ  ej                  de       	 ddlZddlZ G d d      Z
dd	Zd
 Zd Zy# e$ r ddlm	Z	  e	d      dw xY w)a  Code for doing logistic regressions (DEPRECATED).

Classes:
 - LogisticRegression    Holds information for a LogisticRegression classifier.

Functions:
 - train        Train a new classifier.
 - calculate    Calculate the probabilities of each class, given an observation.
 - classify     Classify an observation into a class.

This module has been deprecated, please consider an alternative like scikit-learn
instead.
    N)BiopythonDeprecationWarningzThe 'Bio.LogisticRegression' module is deprecated and will be removed in a future release of Biopython. Consider using scikit-learn instead.)MissingPythonDependencyErrorzYPlease install NumPy if you want to use Bio.LogisticRegression. See http://www.numpy.org/c                       e Zd ZdZd Zy)LogisticRegressionzHolds information necessary to do logistic regression classification.

    Attributes:
     - beta - List of the weights for each dimension.

    c                     g | _         y)zInitialize the class.N)beta)selfs    e/mounts/lovelace/software/anaconda3/envs/py312/lib/python3.12/site-packages/Bio/LogisticRegression.py__init__zLogisticRegression.__init__4   s	    	    N)__name__
__module____qualname____doc__r    r   r
   r   r   ,   s    r   r   c                    t        |       t        |      k7  rt        d      t        |      }|ddhk7  rt        d      |d}t        |       t        | d         dz   }}|dk(  s|dk(  rt        d      t        j                  ||f|      }| |ddddf<   t        j
                  |      }t        j                  ||      }	t        j                  ||      }
d}d	}d
}d}dx}}||k  r\t        j                  t        j                  |
|            }|d|z   z  }|	t        j                  |      z  d|	z
  t        j                  d|z
        z  z   }t        |      }| |t        |       |(||k  r|dz  }|}
t        j                  ||z
        |k  rn||
}}|dz  }t        j                  |      |z  }t        j                  ||	|z
        }t        j                  t        j                  ||      |      }t        j                   j#                  ||      }t        j                  |d
z
        dkD  r||z  }|
|z  }
||k  r\t%        d      t'               }t)        |
      |_        |S )a^  Train a logistic regression classifier on a training set.

    Argument xs is a list of observations and ys is a list of the class
    assignments, which should be 0 or 1.  xs and ys should contain the
    same number of elements.  update_fn is an optional callback function
    that takes as parameters that iteration number and log likelihood.
    z$xs and ys should be the same length.r      zClasses should be 0's and 1'sNdz.No observations or observation of 0 dimension.i  g{Gz?      ?g       @gMbP?zDidn't converge.)len
ValueErrorsetnpones	transposeasarrayzerosexpdotlogsumiterfabsidentitynumpylinalgsolveRuntimeErrorr   listr   )xsys	update_fntypecodeclassesNndimsXXtyr   MAX_ITERATIONSCONVERGE_THRESHOLDstepsizeiold_betaold_llikebetaXplogpllikWXtypXtWXdeltalrs                             r
   trainrC   9   s`    2w#b'?@@"gG1a&899 2wBqE
QuAAv!IJJ 	E
H%AAaeH	aB


2x A 88E8$DNH 	
AHx
n
tR()a&j! 266!9}AA664y dD! hCwwth'+==!4(	QKKNQvvb!a% vvbffRmQ'""4.778c>"U*XE9 n
< -..		B4jBGIr   c                     t        j                  dg|z         }t        j                  t        j                  | j                  |            }|d|z   z  }d|z
  |gS )zCalculate the probability for each class.

    Arguments:
     - lr is a LogisticRegression object.
     - x is the observed data.

    Returns a list of the probability that it fits each class.
    r   r   )r   r   r   r   r   )rB   xr:   r;   s       r
   	calculaterF      sQ     	

C519AVVBFF277A&'F!f*AE1:r   c                 4    t        | |      }|d   |d   kD  ryy)z%Classify an observation into a class.r   r   )rF   )rB   rE   probss      r
   classifyrI      s$    b!EQx%(r   )NN)r   warningsBior   warnr%   r   numpy.linalgImportErrorr   r   rC   rF   rI   r   r   r
   <module>rO      s{     + A	
 
HV"e  0
&	$ s	   > A