
    0Phb                        d Z ddlZddlmZmZ ddlmZmZ ddlZ	ddl
mZ ddlmZmZmZ ddlmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZmZmZmZmZ g dZ  G d deee          Z! G d de!          Z" G d de!          Z# G d de#          Z$ G d de#          Z% G d de#          Z& G d de#          Z'dS )zNaive Bayes algorithms.

These are supervised learning methods based on applying Bayes' theorem with strong
(naive) feature independence assumptions.
    N)ABCMetaabstractmethod)IntegralReal)	logsumexp   )BaseEstimatorClassifierMixin_fit_context)LabelBinarizerbinarizelabel_binarize)Interval)safe_sparse_dot)_check_partial_fit_first_call)_check_n_features_check_sample_weightcheck_is_fittedcheck_non_negativevalidate_data)BernoulliNB
GaussianNBMultinomialNBComplementNBCategoricalNBc                   V    e Zd ZdZed             Zed             Zd Zd Zd Z	d Z
dS )	_BaseNBz.Abstract base class for naive Bayes estimatorsc                     dS )a  Compute the unnormalized posterior log probability of X

        I.e. ``log P(c) + log P(x|c)`` for all rows x of X, as an array-like of
        shape (n_samples, n_classes).

        Public methods predict, predict_proba, predict_log_proba, and
        predict_joint_log_proba pass the input through _check_X before handing it
        over to _joint_log_likelihood. The term "joint log likelihood" is used
        interchangibly with "joint log probability".
        N selfXs     S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sklearn/naive_bayes.py_joint_log_likelihoodz_BaseNB._joint_log_likelihood.             c                     dS )zgTo be overridden in subclasses with the actual checks.

        Only used in predict* methods.
        Nr   r    s     r#   _check_Xz_BaseNB._check_X;   r%   r&   c                 t    t          |            |                     |          }|                     |          S )a  Return joint log probability estimates for the test vector X.

        For each row x of X and class y, the joint log probability is given by
        ``log P(x, y) = log P(y) + log P(x|y),``
        where ``log P(y)`` is the class prior probability and ``log P(x|y)`` is
        the class-conditional probability.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input samples.

        Returns
        -------
        C : ndarray of shape (n_samples, n_classes)
            Returns the joint log-probability of the samples for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute :term:`classes_`.
        )r   r(   r$   r    s     r#   predict_joint_log_probaz_BaseNB.predict_joint_log_probaB   s7    ( 	MM!))!,,,r&   c                     t          |            |                     |          }|                     |          }| j        t	          j        |d                   S )a;  
        Perform classification on an array of test vectors X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input samples.

        Returns
        -------
        C : ndarray of shape (n_samples,)
            Predicted target values for X.
        r   axis)r   r(   r$   classes_npargmaxr!   r"   jlls      r#   predictz_BaseNB.predictZ   sR     	MM!((++}RYs33344r&   c                     t          |            |                     |          }|                     |          }t          |d          }|t	          j        |          j        z
  S )a  
        Return log-probability estimates for the test vector X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input samples.

        Returns
        -------
        C : array-like of shape (n_samples, n_classes)
            Returns the log-probability of the samples for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute :term:`classes_`.
        r   r,   )r   r(   r$   r   r/   
atleast_2dT)r!   r"   r2   
log_prob_xs       r#   predict_log_probaz_BaseNB.predict_log_probam   s`      	MM!((++s+++
R]:..000r&   c                 P    t          j        |                     |                    S )a  
        Return probability estimates for the test vector X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            The input samples.

        Returns
        -------
        C : array-like of shape (n_samples, n_classes)
            Returns the probability of the samples for each class in
            the model. The columns correspond to the classes in sorted
            order, as they appear in the attribute :term:`classes_`.
        )r/   expr8   r    s     r#   predict_probaz_BaseNB.predict_proba   s"      vd,,Q//000r&   N)__name__
__module____qualname____doc__r   r$   r(   r*   r3   r8   r;   r   r&   r#   r   r   +   s        88
 
 ^
   ^- - -05 5 5&1 1 1.1 1 1 1 1r&   r   )	metaclassc                       e Zd ZU dZddg eeddd          gdZeed<   dd	dd
Z	 e
d          dd            Zd Zedd            Z e
d          dd            ZddZd ZdS )r   a	  
    Gaussian Naive Bayes (GaussianNB).

    Can perform online updates to model parameters via :meth:`partial_fit`.
    For details on algorithm used to update feature means and variance online,
    see `Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque
    <http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf>`_.

    Read more in the :ref:`User Guide <gaussian_naive_bayes>`.

    Parameters
    ----------
    priors : array-like of shape (n_classes,), default=None
        Prior probabilities of the classes. If specified, the priors are not
        adjusted according to the data.

    var_smoothing : float, default=1e-9
        Portion of the largest variance of all features that is added to
        variances for calculation stability.

        .. versionadded:: 0.20

    Attributes
    ----------
    class_count_ : ndarray of shape (n_classes,)
        number of training samples observed in each class.

    class_prior_ : ndarray of shape (n_classes,)
        probability of each class.

    classes_ : ndarray of shape (n_classes,)
        class labels known to the classifier.

    epsilon_ : float
        absolute additive value to variances.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    var_ : ndarray of shape (n_classes, n_features)
        Variance of each feature per class.

        .. versionadded:: 1.0

    theta_ : ndarray of shape (n_classes, n_features)
        mean of each feature per class.

    See Also
    --------
    BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.
    CategoricalNB : Naive Bayes classifier for categorical features.
    ComplementNB : Complement Naive Bayes classifier.
    MultinomialNB : Naive Bayes classifier for multinomial models.

    Examples
    --------
    >>> import numpy as np
    >>> X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]])
    >>> Y = np.array([1, 1, 1, 2, 2, 2])
    >>> from sklearn.naive_bayes import GaussianNB
    >>> clf = GaussianNB()
    >>> clf.fit(X, Y)
    GaussianNB()
    >>> print(clf.predict([[-0.8, -1]]))
    [1]
    >>> clf_pf = GaussianNB()
    >>> clf_pf.partial_fit(X, Y, np.unique(Y))
    GaussianNB()
    >>> print(clf_pf.predict([[-0.8, -1]]))
    [1]
    
array-likeNr   leftclosedpriorsvar_smoothing_parameter_constraintsg&.>c                "    || _         || _        d S NrF   )r!   rG   rH   s      r#   __init__zGaussianNB.__init__   s    *r&   Tprefer_skip_nested_validationc                 |    t          | |          }|                     ||t          j        |          d|          S )a  Fit Gaussian Naive Bayes according to X, y.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples
            and `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target values.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

            .. versionadded:: 0.17
               Gaussian Naive Bayes supports fitting with *sample_weight*.

        Returns
        -------
        self : object
            Returns the instance itself.
        )yT_refitsample_weight)r   _partial_fitr/   unique)r!   r"   rP   rS   s       r#   fitzGaussianNB.fit   sF    0 $!$$$  q")A,,t= ! 
 
 	
r&   c                 &    t          | |d          S )*Validate X, used only in predict* methods.Fresetr   r    s     r#   r(   zGaussianNB._check_X  s    T1E2222r&   c                 (   |j         d         dk    r||fS |ot          |                                          }t          j        |d          r||fS t          j        |d|          }t          j        ||z
  dz  d|          }n9|j         d         }t          j        |d          }t          j        |d          }| dk    r||fS t          | |z             }||z  | |z  z   |z  }	| |z  }
||z  }|
|z   || z  |z  ||z
  dz  z  z   }||z  }|	|fS )a  Compute online update of Gaussian mean and variance.

        Given starting sample count, mean, and variance, a new set of
        points X, and optionally sample weights, return the updated mean and
        variance. (NB - each dimension (column) in X is treated as independent
        -- you get variance, not covariance).

        Can take scalar mean and variance, or vector mean and variance to
        simultaneously update a number of independent Gaussians.

        See Stanford CS tech report STAN-CS-79-773 by Chan, Golub, and LeVeque:

        http://i.stanford.edu/pub/cstr/reports/cs/tr/79/773/CS-TR-79-773.pdf

        Parameters
        ----------
        n_past : int
            Number of samples represented in old mean and variance. If sample
            weights were given, this should contain the sum of sample
            weights represented in old mean and variance.

        mu : array-like of shape (number of Gaussians,)
            Means for Gaussians in original set.

        var : array-like of shape (number of Gaussians,)
            Variances for Gaussians in original set.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

        Returns
        -------
        total_mu : array-like of shape (number of Gaussians,)
            Updated mean for each Gaussian over the combined set.

        total_var : array-like of shape (number of Gaussians,)
            Updated variance for each Gaussian over the combined set.
        r   N        )r-   weights   r,   )shapefloatsumr/   iscloseaveragevarmean)n_pastmure   r"   rS   n_newnew_munew_varn_totaltotal_muold_ssdnew_ssd	total_ssd	total_vars                 r#   _update_mean_variancez GaussianNB._update_mean_variance  sR   P 71:??s7N $-++--..Ez%%% 3wZ=AAAFj!f*!2MRRRGGGAJEfQQ'''GWQQ'''FQ;;7?"'' FNVb[0G;
 3,'/g%')Ab6kVWEW(WW	'	""r&   c                 6    |                      |||d|          S )a{  Incremental fit on a batch of samples.

        This method is expected to be called several times consecutively
        on different chunks of a dataset so as to implement out-of-core
        or online learning.

        This is especially useful when the whole dataset is too big to fit in
        memory at once.

        This method has some performance and numerical stability overhead,
        hence it is better to call partial_fit on chunks of data that are
        as large as possible (as long as fitting in the memory budget) to
        hide the overhead.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target values.

        classes : array-like of shape (n_classes,), default=None
            List of all the classes that can possibly appear in the y vector.

            Must be provided at the first call to partial_fit, can be omitted
            in subsequent calls.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

            .. versionadded:: 0.17

        Returns
        -------
        self : object
            Returns the instance itself.
        FrQ   )rT   )r!   r"   rP   classesrS   s        r#   partial_fitzGaussianNB.partial_fit\  s-    R   q'%} ! 
 
 	
r&   Fc           	         |rd| _         t          | |          }t          | |||          \  }}|t          ||          }| j        t          j        |d                                          z  | _        |r[|j	        d         }t          | j                   }t          j        ||f          | _        t          j        ||f          | _        t          j        |t
          j                  | _        | j        t          j        | j                  }	t          |	          |k    rt%          d          t          j        |	                                d          st%          d	          |	dk                                     rt%          d
          |	| _        nt          j        t          | j                   t
          j                  | _        nr|j	        d         | j        j	        d         k    r1d}
t%          |
|j	        d         | j        j	        d         fz            | j        ddddfxx         | j        z  cc<   | j         }t          j        |          }t          j        ||          }t          j        |          st%          d||          d|          |D ]}|                    |          }|||k    ddf         }|!|||k             }|                                }nd}|j	        d         }|                     | j        |         | j        |ddf         | j        |ddf         ||          \  }}|| j        |ddf<   || j        |ddf<   | j        |xx         |z  cc<   | j        ddddfxx         | j        z  cc<   | j        &| j        | j                                        z  | _        | S )a  Actual implementation of Gaussian NB fitting.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target values.

        classes : array-like of shape (n_classes,), default=None
            List of all the classes that can possibly appear in the y vector.

            Must be provided at the first call to partial_fit, can be omitted
            in subsequent calls.

        _refit : bool, default=False
            If true, act as though this were the first time we called
            _partial_fit (ie, throw away any past fitting and start over).

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

        Returns
        -------
        self : object
        NrY   r   r,   r   dtype.Number of priors must match number of classes.      ?z"The sum of the priors should be 1.zPriors must be non-negative.z6Number of features %d does not match previous data %d.zThe target label(s) z* in y do not exist in the initial classes )r.   r   r   r   rH   r/   re   maxepsilon_r`   lenzerostheta_var_float64class_count_rG   asarray
ValueErrorrc   rb   anyclass_prior_rU   isinallsearchsortedrr   )r!   r"   rP   rt   rR   rS   
first_call
n_features	n_classesrG   msgunique_yunique_y_in_classesy_iiX_isw_iN_i	new_theta	new_sigmas                       r#   rT   zGaussianNB._partial_fit  s   :  	! DM24AA
T1az:::1$0BBM *RVAA->->->-B-B-D-DD  	- JDM**I(Iz#:;;DK)Z!899DI ""* E E ED {&DK00v;;)++$%UVVVz&**,,44 K$%IJJJQJ##%% E$%CDDD$*!! %'HS-?-?rz$R$R$R!!wqzT[.q111N 
DK4Ea4H'I!IJJJIaaadOOOt},OOO-9Q<< gh88v)** 	*0011177<  
  	( 	(C$$S))AAHaaaK.C($Q#X.hhjjil#'#=#=!!$dk!QQQ$&71aaa4#t$ $ Iy !*DK111'DIadOa   C'    	!!!QQQ$4=( ; $ 1D4E4I4I4K4K KDr&   c                    g }t          t          j        | j                            D ]}t          j        | j        |                   }dt          j        t          j        dt          j        z  | j        |d d f         z                      z  }|dt          j        || j	        |d d f         z
  dz  | j        |d d f         z  d          z  z  }|
                    ||z              t          j        |          j        }|S )Ng      g       @g      ?r_   r   )ranger/   sizer.   logr   rb   pir   r   appendarrayr6   )r!   r"   joint_log_likelihoodr   jointin_ijs         r#   r$   z GaussianNB._joint_log_likelihood  s    !rwt}--.. 	7 	7AVD-a011F"&bedi111o(E!F!FGGGDC"&1t{1aaa4'8#8Q">49QPQPQPQT?!SUVWWWWD ''6666!x(<==?##r&   rK   NN)NFN)r<   r=   r>   r?   r   r   rI   dict__annotations__rL   r   rV   r(   staticmethodrr   ru   rT   r$   r   r&   r#   r   r      s=        N Nb  &"(4D@@@A$ $D   
 "&T + + + + + \555
 
 
 65
83 3 3 G# G# G# \G#R \555*
 *
 *
 65*
Xr r r rh	$ 	$ 	$ 	$ 	$r&   r   c                       e Zd ZU dZ eeddd          dgdgddgdgdZeed	<   ddZ	e
d             Ze
d             Zd ZddZddZd Z ed          dd            Z ed          dd            Zd Z fdZ xZS )_BaseDiscreteNBzAbstract base class for naive Bayes on discrete/categorical data

    Any estimator based on this class should provide:

    __init__
    _joint_log_likelihood(X) as per _BaseNB
    _update_feature_log_prob(alpha)
    _count(X, Y)
    r   NrC   rD   rB   booleanalpha	fit_priorclass_priorforce_alpharI   rz   Tc                 >    || _         || _        || _        || _        d S rK   r   )r!   r   r   r   r   s        r#   rL   z_BaseDiscreteNB.__init__  s&    
"&&r&   c                     dS )a=  Update counts that are used to calculate probabilities.

        The counts make up a sufficient statistic extracted from the data.
        Accordingly, this method is called each time `fit` or `partial_fit`
        update the model. `class_count_` and `feature_count_` must be updated
        here along with any model specific counts.

        Parameters
        ----------
        X : {ndarray, sparse matrix} of shape (n_samples, n_features)
            The input samples.
        Y : ndarray of shape (n_samples, n_classes)
            Binarized class labels.
        Nr   r!   r"   Ys      r#   _countz_BaseDiscreteNB._count!  r%   r&   c                     dS )a  Update feature log probabilities based on counts.

        This method is called each time `fit` or `partial_fit` update the
        model.

        Parameters
        ----------
        alpha : float
            smoothing parameter. See :meth:`_check_alpha`.
        Nr   )r!   r   s     r#   _update_feature_log_probz(_BaseDiscreteNB._update_feature_log_prob2  r%   r&   c                 (    t          | |dd          S )rX   csrFaccept_sparserZ   r[   r    s     r#   r(   z_BaseDiscreteNB._check_X?  s    T1EGGGGr&   c                 *    t          | ||d|          S )z Validate X and y in fit methods.r   r   r[   r!   r"   rP   rZ   s       r#   
_check_X_yz_BaseDiscreteNB._check_X_yC  s    T1auEJJJJr&   c                 :   t          | j                  }|=t          |          |k    rt          d          t          j        |          | _        dS | j        rt          j                    5  t          j	        dt                     t          j        | j                  }ddd           n# 1 swxY w Y   |t          j        | j                                                  z
  | _        dS t          j        |t          j        |                     | _        dS )zUpdate class log priors.

        The class log priors are based on `class_prior`, class count or the
        number of classes. This method is called each time `fit` or
        `partial_fit` update the model.
        Nry   ignore)r}   r.   r   r/   r   class_log_prior_r   warningscatch_warningssimplefilterRuntimeWarningr   rb   full)r!   r   r   log_class_counts       r#   _update_class_log_priorz'_BaseDiscreteNB._update_class_log_priorG  s>    &&	";9,, !QRRR$&F;$7$7D!!!^ 
	K(** < < %h???"$&):";";	< < < < < < < < < < < < < < < %4bfT=N=R=R=T=T6U6U$UD!!!$&GIy8I8I7I$J$JD!!!s   .4B..B25B2c                    t          | j        t                    st          j        | j                  n| j        }t          j        |          }t          |t          j                  rQ|j        d         | j        k    s&t          d|j        d          d| j         d          |dk     rt          d          d}||k     r5| j
        s.t          j        d|dd	           t          j        ||          S |S )
Nr   z=When alpha is an array, it should contains `n_features`. Got z elements instead of .z+All values in alpha must be greater than 0.g|=z?alpha too small will result in numeric errors, setting alpha = z.1ez1. Use `force_alpha=True` to keep alpha unchanged.)
isinstancer   r   r/   r   minndarrayr`   n_features_in_r   r   r   warnmaximum)r!   r   	alpha_minalpha_lower_bounds       r#   _check_alphaz_BaseDiscreteNB._check_alpha_  s'   *4TZ*F*FVBJtz"""DJ 	 F5MM	eRZ(( 	P;q>T%888 W ;q>W W@D@SW W W  
 1}} !NOOO!(((1A(M%Q    
 :e%6777r&   rM   c                    t          | d           }|                     |||          \  }}|j        \  }}t          | |          r%t	          |          }|                     ||           t          || j                  }	|	j        d         dk    rHt	          | j                  dk    rt          j	        d|	z
  |	fd          }	nt          j
        |	          }	|j        d         |	j        d         k    r,d}
t          |
|j        d         |j        d         fz            |	                    t          j        d	
          }	|.t          ||          }t          j        |          }|	|j        z  }	| j        }|                     ||	           |                                 }|                     |           |                     |           | S )aG  Incremental fit on a batch of samples.

        This method is expected to be called several times consecutively
        on different chunks of a dataset so as to implement out-of-core
        or online learning.

        This is especially useful when the whole dataset is too big to fit in
        memory at once.

        This method has some performance overhead hence it is better to call
        partial_fit on chunks of data that are as large as possible
        (as long as fitting in the memory budget) to hide the overhead.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target values.

        classes : array-like of shape (n_classes,), default=None
            List of all the classes that can possibly appear in the y vector.

            Must be provided at the first call to partial_fit, can be omitted
            in subsequent calls.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

        Returns
        -------
        self : object
            Returns the instance itself.
        r.   rY   )rt   r   r_   r,   r   z1X.shape[0]=%d and y.shape[0]=%d are incompatible.FcopyNr   )hasattrr   r`   r   r}   _init_countersr   r.   r/   concatenate	ones_liker   astyper   r   r5   r6   r   r   r   r   r   )r!   r"   rP   rt   rS   r   _r   r   r   r   r   r   s                r#   ru   z_BaseDiscreteNB.partial_fitw  s   L !z222
q!:661:(w77 	7 GI	:6661dm44471:??4=!!Q&&NAE1:A666LOO71:##ECSAGAJ
#;;<<< HHRZeH,,$0BBMM-88M A& 	Aq !!##%%e,,,$$$===r&   c                    |                      ||          \  }}|j        \  }}t                      }|                    |          }|j        | _        |j        d         dk    rHt          | j                  dk    rt          j        d|z
  |fd          }nt          j        |          }|O|	                    t          j
        d          }t          ||          }t          j        |          }||j        z  }| j        }|j        d         }	|                     |	|           |                     ||           |                                 }
|                     |
           |                     |           | S )a_  Fit Naive Bayes classifier according to X, y.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features.

        y : array-like of shape (n_samples,)
            Target values.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

        Returns
        -------
        self : object
            Returns the instance itself.
        r   r_   r,   NFr   r   )r   r`   r   fit_transformr.   r}   r/   r   r   r   r   r   r5   r6   r   r   r   r   r   r   )r!   r"   rP   rS   r   r   labelbinr   r   r   r   s              r#   rV   z_BaseDiscreteNB.fit  sf   * q!$$1:!##""1%% )71:??4=!!Q&&NAE1:A666LOO
 $%00A0BBMM-88M A& GAJ	Iz222Aq!!##%%e,,,$$$===r&   c                     t          j        |t           j                  | _        t          j        ||ft           j                  | _        d S )Nrw   )r/   r~   r   r   feature_count_r!   r   r   s      r#   r   z_BaseDiscreteNB._init_counters   s?    HYbjAAA h	:'>bjQQQr&   c                 x    t                                                      }d|j        _        d|j        _        |S NT)super__sklearn_tags__
input_tagssparseclassifier_tags
poor_scorer!   tags	__class__s     r#   r   z _BaseDiscreteNB.__sklearn_tags__  s2    ww''))!%*.'r&   )rz   TNTTrK   r   )r<   r=   r>   r?   r   r   rI   r   r   rL   r   r   r   r(   r   r   r   r   ru   rV   r   r   __classcell__r   s   @r#   r   r   	  s          (4D888,G[$d+!{	$ $D   ' ' ' '   ^  
 
 ^
H H HK K K KK K K K0  0 \555P P P 65Pd \5553 3 3 653jR R R        r&   r   c                   J     e Zd ZdZddddd fd
Z fdZd Zd	 Zd
 Z xZ	S )r   a  
    Naive Bayes classifier for multinomial models.

    The multinomial Naive Bayes classifier is suitable for classification with
    discrete features (e.g., word counts for text classification). The
    multinomial distribution normally requires integer feature counts. However,
    in practice, fractional counts such as tf-idf may also work.

    Read more in the :ref:`User Guide <multinomial_naive_bayes>`.

    Parameters
    ----------
    alpha : float or array-like of shape (n_features,), default=1.0
        Additive (Laplace/Lidstone) smoothing parameter
        (set alpha=0 and force_alpha=True, for no smoothing).

    force_alpha : bool, default=True
        If False and alpha is less than 1e-10, it will set alpha to
        1e-10. If True, alpha will remain unchanged. This may cause
        numerical errors if alpha is too close to 0.

        .. versionadded:: 1.2
        .. versionchanged:: 1.4
           The default value of `force_alpha` changed to `True`.

    fit_prior : bool, default=True
        Whether to learn class prior probabilities or not.
        If false, a uniform prior will be used.

    class_prior : array-like of shape (n_classes,), default=None
        Prior probabilities of the classes. If specified, the priors are not
        adjusted according to the data.

    Attributes
    ----------
    class_count_ : ndarray of shape (n_classes,)
        Number of samples encountered for each class during fitting. This
        value is weighted by the sample weight when provided.

    class_log_prior_ : ndarray of shape (n_classes,)
        Smoothed empirical log probability for each class.

    classes_ : ndarray of shape (n_classes,)
        Class labels known to the classifier

    feature_count_ : ndarray of shape (n_classes, n_features)
        Number of samples encountered for each (class, feature)
        during fitting. This value is weighted by the sample weight when
        provided.

    feature_log_prob_ : ndarray of shape (n_classes, n_features)
        Empirical log probability of features
        given a class, ``P(x_i|y)``.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.
    CategoricalNB : Naive Bayes classifier for categorical features.
    ComplementNB : Complement Naive Bayes classifier.
    GaussianNB : Gaussian Naive Bayes.

    References
    ----------
    C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to
    Information Retrieval. Cambridge University Press, pp. 234-265.
    https://nlp.stanford.edu/IR-book/html/htmledition/naive-bayes-text-classification-1.html

    Examples
    --------
    >>> import numpy as np
    >>> rng = np.random.RandomState(1)
    >>> X = rng.randint(5, size=(6, 100))
    >>> y = np.array([1, 2, 3, 4, 5, 6])
    >>> from sklearn.naive_bayes import MultinomialNB
    >>> clf = MultinomialNB()
    >>> clf.fit(X, y)
    MultinomialNB()
    >>> print(clf.predict(X[2:3]))
    [3]
    rz   TNr   r   r   r   c                R    t                                          ||||           d S Nr   )r   rL   )r!   r   r   r   r   r   s        r#   rL   zMultinomialNB.__init__h  s<     	##	 	 	
 	
 	
 	
 	
r&   c                 `    t                                                      }d|j        _        |S r   r   r   r   positive_onlyr   s     r#   r   zMultinomialNB.__sklearn_tags__r  '    ww''))(,%r&   c                     t          |d           | xj        t          |j        |          z  c_        | xj        |                    d          z  c_        dS )%Count and smooth feature occurrences.zMultinomialNB (input X)r   r,   N)r   r   r   r6   r   rb   r   s      r#   r   zMultinomialNB._countw  sY    17888qsA666QUUU]]*r&   c                     | j         |z   }|                    d          }t          j        |          t          j        |                    dd                    z
  | _        dS )=Apply smoothing to raw counts and recompute log probabilitiesr   r,   N)r   rb   r/   r   reshapefeature_log_prob_r!   r   smoothed_fcsmoothed_ccs       r#   r   z&MultinomialNB._update_feature_log_prob}  s`    )E1!oo1o--!#!4!4rvA&&8
 8
 "
r&   c                 F    t          || j        j                  | j        z   S )8Calculate the posterior log probability of the samples X)r   r   r6   r   r    s     r#   r$   z#MultinomialNB._joint_log_likelihood  s     q$"8":;;d>SSSr&   )
r<   r=   r>   r?   rL   r   r   r   r$   r   r   s   @r#   r   r     s        Z Zz $
 
 
 
 
 
 
    
+ + +
 
 
T T T T T T Tr&   r   c                   t     e Zd ZU dZi ej        ddgiZeed<   dddddd	 fd

Z fdZ	d Z
d Zd Z xZS )r   aV  The Complement Naive Bayes classifier described in Rennie et al. (2003).

    The Complement Naive Bayes classifier was designed to correct the "severe
    assumptions" made by the standard Multinomial Naive Bayes classifier. It is
    particularly suited for imbalanced data sets.

    Read more in the :ref:`User Guide <complement_naive_bayes>`.

    .. versionadded:: 0.20

    Parameters
    ----------
    alpha : float or array-like of shape (n_features,), default=1.0
        Additive (Laplace/Lidstone) smoothing parameter
        (set alpha=0 and force_alpha=True, for no smoothing).

    force_alpha : bool, default=True
        If False and alpha is less than 1e-10, it will set alpha to
        1e-10. If True, alpha will remain unchanged. This may cause
        numerical errors if alpha is too close to 0.

        .. versionadded:: 1.2
        .. versionchanged:: 1.4
           The default value of `force_alpha` changed to `True`.

    fit_prior : bool, default=True
        Only used in edge case with a single class in the training set.

    class_prior : array-like of shape (n_classes,), default=None
        Prior probabilities of the classes. Not used.

    norm : bool, default=False
        Whether or not a second normalization of the weights is performed. The
        default behavior mirrors the implementations found in Mahout and Weka,
        which do not follow the full algorithm described in Table 9 of the
        paper.

    Attributes
    ----------
    class_count_ : ndarray of shape (n_classes,)
        Number of samples encountered for each class during fitting. This
        value is weighted by the sample weight when provided.

    class_log_prior_ : ndarray of shape (n_classes,)
        Smoothed empirical log probability for each class. Only used in edge
        case with a single class in the training set.

    classes_ : ndarray of shape (n_classes,)
        Class labels known to the classifier

    feature_all_ : ndarray of shape (n_features,)
        Number of samples encountered for each feature during fitting. This
        value is weighted by the sample weight when provided.

    feature_count_ : ndarray of shape (n_classes, n_features)
        Number of samples encountered for each (class, feature) during fitting.
        This value is weighted by the sample weight when provided.

    feature_log_prob_ : ndarray of shape (n_classes, n_features)
        Empirical weights for class complements.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.
    CategoricalNB : Naive Bayes classifier for categorical features.
    GaussianNB : Gaussian Naive Bayes.
    MultinomialNB : Naive Bayes classifier for multinomial models.

    References
    ----------
    Rennie, J. D., Shih, L., Teevan, J., & Karger, D. R. (2003).
    Tackling the poor assumptions of naive bayes text classifiers. In ICML
    (Vol. 3, pp. 616-623).
    https://people.csail.mit.edu/jrennie/papers/icml03-nb.pdf

    Examples
    --------
    >>> import numpy as np
    >>> rng = np.random.RandomState(1)
    >>> X = rng.randint(5, size=(6, 100))
    >>> y = np.array([1, 2, 3, 4, 5, 6])
    >>> from sklearn.naive_bayes import ComplementNB
    >>> clf = ComplementNB()
    >>> clf.fit(X, y)
    ComplementNB()
    >>> print(clf.predict(X[2:3]))
    [3]
    normr   rI   rz   TNF)r   r   r   r   r  c                `    t                                          ||||           || _        d S Nr   )r   rL   r  )r!   r   r   r   r   r  r   s         r#   rL   zComplementNB.__init__  s?     	##	 	 	
 	
 	
 			r&   c                 `    t                                                      }d|j        _        |S r   r   r   s     r#   r   zComplementNB.__sklearn_tags__  r   r&   c                     t          |d           | xj        t          |j        |          z  c_        | xj        |                    d          z  c_        | j                            d          | _        dS )zCount feature occurrences.zComplementNB (input X)r   r,   N)r   r   r   r6   r   rb   feature_all_r   s      r#   r   zComplementNB._count  su    16777qsA666QUUU]]* /333;;r&   c                     | j         |z   | j        z
  }t          j        ||                    dd          z            }| j        r|                    dd          }||z  }n| }|| _        dS )z6Apply smoothing to raw counts and compute the weights.r   T)r-   keepdimsN)r  r   r/   r   rb   r  r   )r!   r   
comp_countloggedsummedfeature_log_probs         r#   r   z%ComplementNB._update_feature_log_prob  s}    &.1DD

Z^^T^%J%JJKK9 	'ZZQZ66F% &w!1r&   c                 ~    t          || j        j                  }t          | j                  dk    r
|| j        z  }|S )z0Calculate the class scores for the samples in X.r   )r   r   r6   r}   r.   r   r1   s      r#   r$   z"ComplementNB._joint_log_likelihood  s>    a!7!9::t}""4((C
r&   )r<   r=   r>   r?   r   rI   r   r   rL   r   r   r   r$   r   r   s   @r#   r   r     s         b bH$

0$$ $D          "    
< < <
2 
2 
2      r&   r   c            	            e Zd ZU dZi ej        dd eeddd          giZee	d<   dd	d
d	dd fd
Z
 fdZd fd	Zd Zd Zd Z xZS )r   a  Naive Bayes classifier for multivariate Bernoulli models.

    Like MultinomialNB, this classifier is suitable for discrete data. The
    difference is that while MultinomialNB works with occurrence counts,
    BernoulliNB is designed for binary/boolean features.

    Read more in the :ref:`User Guide <bernoulli_naive_bayes>`.

    Parameters
    ----------
    alpha : float or array-like of shape (n_features,), default=1.0
        Additive (Laplace/Lidstone) smoothing parameter
        (set alpha=0 and force_alpha=True, for no smoothing).

    force_alpha : bool, default=True
        If False and alpha is less than 1e-10, it will set alpha to
        1e-10. If True, alpha will remain unchanged. This may cause
        numerical errors if alpha is too close to 0.

        .. versionadded:: 1.2
        .. versionchanged:: 1.4
           The default value of `force_alpha` changed to `True`.

    binarize : float or None, default=0.0
        Threshold for binarizing (mapping to booleans) of sample features.
        If None, input is presumed to already consist of binary vectors.

    fit_prior : bool, default=True
        Whether to learn class prior probabilities or not.
        If false, a uniform prior will be used.

    class_prior : array-like of shape (n_classes,), default=None
        Prior probabilities of the classes. If specified, the priors are not
        adjusted according to the data.

    Attributes
    ----------
    class_count_ : ndarray of shape (n_classes,)
        Number of samples encountered for each class during fitting. This
        value is weighted by the sample weight when provided.

    class_log_prior_ : ndarray of shape (n_classes,)
        Log probability of each class (smoothed).

    classes_ : ndarray of shape (n_classes,)
        Class labels known to the classifier

    feature_count_ : ndarray of shape (n_classes, n_features)
        Number of samples encountered for each (class, feature)
        during fitting. This value is weighted by the sample weight when
        provided.

    feature_log_prob_ : ndarray of shape (n_classes, n_features)
        Empirical log probability of features given a class, P(x_i|y).

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    CategoricalNB : Naive Bayes classifier for categorical features.
    ComplementNB : The Complement Naive Bayes classifier
        described in Rennie et al. (2003).
    GaussianNB : Gaussian Naive Bayes (GaussianNB).
    MultinomialNB : Naive Bayes classifier for multinomial models.

    References
    ----------
    C.D. Manning, P. Raghavan and H. Schuetze (2008). Introduction to
    Information Retrieval. Cambridge University Press, pp. 234-265.
    https://nlp.stanford.edu/IR-book/html/htmledition/the-bernoulli-model-1.html

    A. McCallum and K. Nigam (1998). A comparison of event models for naive
    Bayes text classification. Proc. AAAI/ICML-98 Workshop on Learning for
    Text Categorization, pp. 41-48.

    V. Metsis, I. Androutsopoulos and G. Paliouras (2006). Spam filtering with
    naive Bayes -- Which naive Bayes? 3rd Conf. on Email and Anti-Spam (CEAS).

    Examples
    --------
    >>> import numpy as np
    >>> rng = np.random.RandomState(1)
    >>> X = rng.randint(5, size=(6, 100))
    >>> Y = np.array([1, 2, 3, 4, 4, 5])
    >>> from sklearn.naive_bayes import BernoulliNB
    >>> clf = BernoulliNB()
    >>> clf.fit(X, Y)
    BernoulliNB()
    >>> print(clf.predict(X[2:3]))
    [3]
    r   Nr   rC   rD   rI   rz   Tr]   )r   r   r   r   r   c                `    t                                          ||||           || _        d S r   )r   rL   r   )r!   r   r   r   r   r   r   s         r#   rL   zBernoulliNB.__init__  s?     	##	 	 	
 	
 	
 !r&   c                     t                                          |          }| j        t          || j                  }|S )rX   N	threshold)r   r(   r   )r!   r"   r   s     r#   r(   zBernoulliNB._check_X  s;    GGQ=$dm444Ar&   c                     t                                          |||          \  }}| j        t          || j                  }||fS )NrY   r  )r   r   r   )r!   r"   rP   rZ   r   s       r#   r   zBernoulliNB._check_X_y  sJ    ww!!!Qe!441=$dm444A!tr&   c                     | xj         t          |j        |          z  c_         | xj        |                    d          z  c_        dS )r   r   r,   N)r   r   r6   r   rb   r   s      r#   r   zBernoulliNB._count  sH    qsA666QUUU]]*r&   c                     | j         |z   }| j        |dz  z   }t          j        |          t          j        |                    dd                    z
  | _        dS )r   r_   r   r   N)r   r   r/   r   r   r   r   s       r#   r   z$BernoulliNB._update_feature_log_prob  s^    )E1'%!)3!#!4!4rvA&&8
 8
 "
r&   c                 P   | j         j        d         }|j        d         }||k    rt          d||fz            t          j        dt          j        | j                   z
            }t          || j         |z
  j                  }|| j        |	                    d          z   z  }|S )r  r   z/Expected input with %d features, got %d insteadr,   )
r   r`   r   r/   r   r:   r   r6   r   rb   )r!   r"   r   n_features_Xneg_probr2   s         r#   r$   z!BernoulliNB._joint_log_likelihood  s    +1!4
wqz:%%A|,-  
 6!bfT%;<<<==a$"88"C!FGGt$x|||';';;;
r&   r   )r<   r=   r>   r?   r   rI   r   r   r   r   rL   r(   r   r   r   r$   r   r   s   @r#   r   r   &  s        c cJ$

0$T88D!T&AAAB$ $D    ! ! ! ! ! ! !"         + + +

 
 
      r&   r   c            	            e Zd ZU dZi ej        dd eeddd          g eeddd          gdZe	e
d	<   d
ddddd fd
Zd fd	Zd fd	Z fdZd ZddZd Zed             Zd Zd Zd Z xZS )r   a4  Naive Bayes classifier for categorical features.

    The categorical Naive Bayes classifier is suitable for classification with
    discrete features that are categorically distributed. The categories of
    each feature are drawn from a categorical distribution.

    Read more in the :ref:`User Guide <categorical_naive_bayes>`.

    Parameters
    ----------
    alpha : float, default=1.0
        Additive (Laplace/Lidstone) smoothing parameter
        (set alpha=0 and force_alpha=True, for no smoothing).

    force_alpha : bool, default=True
        If False and alpha is less than 1e-10, it will set alpha to
        1e-10. If True, alpha will remain unchanged. This may cause
        numerical errors if alpha is too close to 0.

        .. versionadded:: 1.2
        .. versionchanged:: 1.4
           The default value of `force_alpha` changed to `True`.

    fit_prior : bool, default=True
        Whether to learn class prior probabilities or not.
        If false, a uniform prior will be used.

    class_prior : array-like of shape (n_classes,), default=None
        Prior probabilities of the classes. If specified, the priors are not
        adjusted according to the data.

    min_categories : int or array-like of shape (n_features,), default=None
        Minimum number of categories per feature.

        - integer: Sets the minimum number of categories per feature to
          `n_categories` for each features.
        - array-like: shape (n_features,) where `n_categories[i]` holds the
          minimum number of categories for the ith column of the input.
        - None (default): Determines the number of categories automatically
          from the training data.

        .. versionadded:: 0.24

    Attributes
    ----------
    category_count_ : list of arrays of shape (n_features,)
        Holds arrays of shape (n_classes, n_categories of respective feature)
        for each feature. Each array provides the number of samples
        encountered for each class and category of the specific feature.

    class_count_ : ndarray of shape (n_classes,)
        Number of samples encountered for each class during fitting. This
        value is weighted by the sample weight when provided.

    class_log_prior_ : ndarray of shape (n_classes,)
        Smoothed empirical log probability for each class.

    classes_ : ndarray of shape (n_classes,)
        Class labels known to the classifier

    feature_log_prob_ : list of arrays of shape (n_features,)
        Holds arrays of shape (n_classes, n_categories of respective feature)
        for each feature. Each array provides the empirical log probability
        of categories given the respective feature and class, ``P(x_i|y)``.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    n_categories_ : ndarray of shape (n_features,), dtype=np.int64
        Number of categories for each feature. This value is
        inferred from the data or set by the minimum number of categories.

        .. versionadded:: 0.24

    See Also
    --------
    BernoulliNB : Naive Bayes classifier for multivariate Bernoulli models.
    ComplementNB : Complement Naive Bayes classifier.
    GaussianNB : Gaussian Naive Bayes.
    MultinomialNB : Naive Bayes classifier for multinomial models.

    Examples
    --------
    >>> import numpy as np
    >>> rng = np.random.RandomState(1)
    >>> X = rng.randint(5, size=(6, 100))
    >>> y = np.array([1, 2, 3, 4, 5, 6])
    >>> from sklearn.naive_bayes import CategoricalNB
    >>> clf = CategoricalNB()
    >>> clf.fit(X, y)
    CategoricalNB()
    >>> print(clf.predict(X[2:3]))
    [3]
    NrB   r   rC   rD   r   )min_categoriesr   rI   rz   T)r   r   r   r   r  c                `    t                                          ||||           || _        d S r  )r   rL   r  )r!   r   r   r   r   r  r   s         r#   rL   zCategoricalNB.__init__B  sB     	##	 	 	
 	
 	
 -r&   c                 L    t                                          |||          S )a  Fit Naive Bayes classifier according to X, y.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features. Here, each feature of X is
            assumed to be from a different categorical distribution.
            It is further assumed that all categories of each feature are
            represented by the numbers 0, ..., n - 1, where n refers to the
            total number of categories for the given feature. This can, for
            instance, be achieved with the help of OrdinalEncoder.

        y : array-like of shape (n_samples,)
            Target values.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

        Returns
        -------
        self : object
            Returns the instance itself.
        rS   )r   rV   )r!   r"   rP   rS   r   s       r#   rV   zCategoricalNB.fitS  s!    2 ww{{1a}{===r&   c                 N    t                                          ||||          S )a  Incremental fit on a batch of samples.

        This method is expected to be called several times consecutively
        on different chunks of a dataset so as to implement out-of-core
        or online learning.

        This is especially useful when the whole dataset is too big to fit in
        memory at once.

        This method has some performance overhead hence it is better to call
        partial_fit on chunks of data that are as large as possible
        (as long as fitting in the memory budget) to hide the overhead.

        Parameters
        ----------
        X : {array-like, sparse matrix} of shape (n_samples, n_features)
            Training vectors, where `n_samples` is the number of samples and
            `n_features` is the number of features. Here, each feature of X is
            assumed to be from a different categorical distribution.
            It is further assumed that all categories of each feature are
            represented by the numbers 0, ..., n - 1, where n refers to the
            total number of categories for the given feature. This can, for
            instance, be achieved with the help of OrdinalEncoder.

        y : array-like of shape (n_samples,)
            Target values.

        classes : array-like of shape (n_classes,), default=None
            List of all the classes that can possibly appear in the y vector.

            Must be provided at the first call to partial_fit, can be omitted
            in subsequent calls.

        sample_weight : array-like of shape (n_samples,), default=None
            Weights applied to individual samples (1. for unweighted).

        Returns
        -------
        self : object
            Returns the instance itself.
        r  )r   ru   )r!   r"   rP   rt   rS   r   s        r#   ru   zCategoricalNB.partial_fitn  s'    T ww""1a"NNNr&   c                 x    t                                                      }d|j        _        d|j        _        |S )NFT)r   r   r   r   r   r   s     r#   r   zCategoricalNB.__sklearn_tags__  s1    ww''))!&(,%r&   c                 P    t          | |dddd          }t          |d           |S )rX   intFTrx   r   ensure_all_finiterZ   CategoricalNB (input X)r   r   r    s     r#   r(   zCategoricalNB._check_X  s@    "
 
 
 	17888r&   c           	      \    t          | ||ddd|          \  }}t          |d           ||fS )Nr#  FTr$  r&  r'  r   s       r#   r   zCategoricalNB._check_X_y  sK    "
 
 
1 	17888!tr&   c                     t          j        t           j                  | _        fdt	          |          D             | _        d S )Nrw   c                 <    g | ]}t          j        d f          S )r   )r/   r~   ).0r   r   s     r#   
<listcomp>z0CategoricalNB._init_counters.<locals>.<listcomp>  s'    TTTQ)Q 8 8TTTr&   )r/   r~   r   r   r   category_count_r   s    ` r#   r   zCategoricalNB._init_counters  sF    HYbjAAATTTT%
BSBSTTTr&   c                    |                      d          dz   }t          j        |          }|t          j        |j        t          j                  st          d|j         d          t          j        ||t          j                  }|j	        |j	        k    r&t          d| j	        d          d|j	         d          |S |S )	Nr   r,   r   z0'min_categories' should have integral type. Got z	 instead.rw   z$'min_categories' should have shape (z',) when an array-like is provided. Got )
r{   r/   r   
issubdtyperx   signedintegerr   r   int64r`   )r"   r  n_categories_Xmin_categories_n_categories_s        r#   _validate_n_categoriesz$CategoricalNB._validate_n_categories  s     A*(>22%=!68HII  8&,8 8 8   J~bhWWWM"n&::: 9171: 9 9'-9 9 9  
 ! !!r&   c                    d }d }| xj         |                    d          z  c_         |                     || j                  | _        t          | j                  D ]d}|d d |f         } || j        |         | j        |         dz
            | j        |<    |||| j        |         | j         j        d                    ed S )Nc                 l    |dz   | j         d         z
  }|dk    rt          j        | dd|fgd          S | S )Nr   r   )r   r   constant)r`   r/   pad)	cat_counthighest_featurediffs      r#   _update_cat_count_dimsz4CategoricalNB._count.<locals>._update_cat_count_dims  sD    "Q&);;Daxxvi&1d))<jIIIr&   c                 \   t          |          D ]}|d d |f                             t                    }|j        j        t
          j        k    rd }n
|||f         }t          j        | |         |          }t          j        |          d         }|||fxx         ||         z  cc<   d S )N)r^   r   )	r   r   boolrx   typer/   r1  bincountnonzero)		X_featurer   r:  r   jmaskr^   countsindicess	            r#   _update_cat_countz/CategoricalNB._count.<locals>._update_cat_count  s    9%% 9 9Aw~~d++7<28++"GGajGYt_gFFF*V,,Q/!W*%%%8%%%%9 9r&   r   r,   r   )	r   rb   r5  r  r4  r   r   r-  r`   )r!   r"   r   r=  rH  r   rC  s          r#   r   zCategoricalNB._count  s    	 	 			9 		9 		9 	QUUU]]*!88D<OPPt*++ 	 	A!!!Q$I&<&<$Q');A)>)B' 'D # 1d215t7H7Nq7Q   	 	r&   c           
      2   g }t          | j                  D ]x}| j        |         |z   }|                    d          }|                    t          j        |          t          j        |                    dd                    z
             y|| _        d S )Nr   r,   r   )	r   r   r-  rb   r   r/   r   r   r   )r!   r   r  r   smoothed_cat_countsmoothed_class_counts         r#   r   z&CategoricalNB._update_feature_log_prob  s    t*++ 	 	A!%!5a!85!@#5#9#9q#9#A#A ##)**RV4H4P4PQSUV4W4W-X-XX    "2r&   c                 $   t          | |d           t          j        |j        d         | j        j        d         f          }t          | j                  D ]-}|d d |f         }|| j        |         d d |f         j        z  }.|| j	        z   }|S )NFrY   r   )
r   r/   r~   r`   r   r   r   r   r6   r   )r!   r"   r2   r   rG  total_lls         r#   r$   z#CategoricalNB._joint_log_likelihood  s    $////h
D$5$;A$>?@@t*++ 	; 	;A1gG4)!,QQQZ8::CC..r&   rK   r   r   )r<   r=   r>   r?   r   rI   r   r   r   r   r   rL   rV   ru   r   r(   r   r   r   r5  r   r   r$   r   r   s   @r#   r   r     s        e eN$

0$ HXq$v666

 (4D8889$ $ $D    - - - - - - -"> > > > > >6*O *O *O *O *O *OX         U U U " " \"*  <2 2 2      r&   r   )(r?   r   abcr   r   numbersr   r   numpyr/   scipy.specialr   baser	   r
   r   preprocessingr   r   r   utils._param_validationr   utils.extmathr   utils.multiclassr   utils.validationr   r   r   r   r   __all__r   r   r   r   r   r   r   r   r&   r#   <module>rY     s     ' ' ' ' ' ' ' ' " " " " " " " "     # # # # # #         
 D C C C C C C C C C - - - - - - * * * * * * ; ; ; ; ; ;               i1 i1 i1 i1 i1o} i1 i1 i1 i1Xo$ o$ o$ o$ o$ o$ o$ o$d    g   D}T }T }T }T }TO }T }T }T@X X X X X? X X Xvg g g g g/ g g gTs s s s sO s s s s sr&   