
    -i                     N   S r SSKrSSKJrJr  SSKJrJr  SSKr	SSK
Jr  SSKJrJrJr  SSKJrJrJr  SS	KJr  SS
KJr  SSKJr  SSKJrJrJrJrJr  / SQr  " S S\\\S9r! " S S\!5      r" " S S\!5      r# " S S\#5      r$ " S S\#5      r% " S S\#5      r& " S S\#5      r'g)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CategoricalNBComplementNB
GaussianNBMultinomialNBc                   P    \ rS rSrSr\S 5       r\S 5       rS rS r	S r
S rS	rg
)_BaseNB+   z.Abstract base class for naive Bayes estimatorsc                     g)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     F/var/www/html/venv/lib/python3.13/site-packages/sklearn/naive_bayes.py_joint_log_likelihood_BaseNB._joint_log_likelihood.           c                     g)zWTo be overridden in subclasses with the actual checks.

Only used in predict* methods.
Nr    r!   s     r$   _check_X_BaseNB._check_X;   r'   r(   c                 \    [        U 5        U R                  U5      nU R                  U5      $ )ax  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_proba_BaseNB.predict_joint_log_probaB   s+    ( 	MM!))!,,r(   c                     [        U 5        U R                  U5      nU R                  U5      nU R                  [        R
                  " USS9   $ )z
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$   predict_BaseNB.predictZ   sD     	MM!((+}}RYYs344r(   c                     [        U 5        U R                  U5      nU R                  U5      n[        USS9nU[        R
                  " U5      R                  -
  $ )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   r0   )r   r*   r%   r   r3   
atleast_2dT)r"   r#   r6   
log_prob_xs       r$   predict_log_proba_BaseNB.predict_log_probam   sP      	MM!((+s+
R]]:.0000r(   c                 L    [         R                  " U R                  U5      5      $ )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_`.
)r3   expr=   r!   s     r$   predict_proba_BaseNB.predict_proba   s      vvd,,Q/00r(   r    N)__name__
__module____qualname____firstlineno____doc__r   r%   r*   r-   r7   r=   rA   __static_attributes__r    r(   r$   r   r   +   s?    8
 
  -05&1.1r(   r   )	metaclassc                       \ rS rSr% SrSS/\" \SSSS9/S.r\\	S	'   SS
S.S jr
\" SS9SS j5       rS r\SS j5       r\" SS9SS j5       rSS jrS rSrg)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                    Xl         X l        g NrP   )r"   rQ   rR   s      r$   __init__GaussianNB.__init__   s    *r(   Tprefer_skip_nested_validationc                 `    [        XS9nU R                  X[        R                  " U5      SUS9$ )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_fitr3   unique)r"   r#   r[   r^   s       r$   fitGaussianNB.fit   s7    0 $$  "))A,t= ! 
 	
r(   c                     [        XSS9$ )*Validate X, used only in predict* methods.Fresetr   r!   s     r$   r*   GaussianNB._check_X  s    TE22r(   c                    UR                   S   S:X  a  X4$ Ubj  [        UR                  5       5      n[        R                  " US5      (       a  X4$ [        R
                  " USUS9n[        R
                  " X6-
  S-  SUS9nO9UR                   S   n[        R                  " USS9n[        R                  " USS9nU S:X  a  Xg4$ [        X-   5      nXV-  X-  -   U-  n	X-  n
XW-  nX-   XP-  U-  X-
  S-  -  -   nX-  nX4$ )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           )r1   weights   r0   )shapefloatsumr3   iscloseaveragevarmean)n_pastmurr   r#   r^   n_newnew_munew_varn_totaltotal_muold_ssdnew_ssd	total_ssd	total_vars                 r$   _update_mean_variance GaussianNB._update_mean_variance  s   P 771:?7N $-++-.Ezz%%%wZZ=AFjj!*!2MRGGGAJEffQQ'GWWQQ'FQ;?"' NV[0G;
 ,/%')AbkVWEW(WW	'	""r(   c                 &    U R                  XUSUS9$ )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.
Fr\   )r_   )r"   r#   r[   classesr^   s        r$   partial_fitGaussianNB.partial_fit\  s&    R   '%} ! 
 	
r(   c           	         U(       a  SU l         [        X5      n[        XX&S9u  pUb  [        XQ5      nU R                  [
        R                  " USS9R                  5       -  U l        U(       Gaf  UR                  S   n[        U R                   5      n[
        R                  " X45      U l        [
        R                  " X45      U l        [
        R                  " U[
        R                  S9U l        U R                   b  [
        R"                  " U R                   5      n	[        U	5      U:w  a  [%        S5      e[
        R&                  " U	R)                  5       S5      (       d  [%        S	5      eU	S:  R+                  5       (       a  [%        S
5      eXl        O[
        R                  " [        U R                   5      [
        R                  S9U l        OUR                  S   U R                  R                  S   :w  a5  Sn
[%        XR                  S   U R                  R                  S   4-  5      eU R                  SS2SS24==   U R                  -  ss'   U R                   n[
        R.                  " U5      n[
        R0                  " X5      n[
        R2                  " U5      (       d  [%        SX)    < SU< 35      eU H  nUR5                  U5      nXU:H  SS24   nUb  XRU:H     nUR)                  5       nOSnUR                  S   nU R7                  U R                  U   U R                  USS24   U R                  USS24   UU5      u  nnUU R                  USS24'   UU R                  USS24'   U R                  U==   U-  ss'   M     U R                  SS2SS24==   U R                  -  ss'   U R                   c,  U R                  U R                  R)                  5       -  U l        U $ )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
Nre   r   r0   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 )r2   r   r   r   rR   r3   rr   maxepsilon_rm   lenzerostheta_var_float64class_count_rQ   asarray
ValueErrorrp   ro   anyclass_prior_r`   isinallsearchsortedr   )r"   r#   r[   r   r]   r^   
first_call
n_features	n_classesrQ   msgunique_yunique_y_in_classesy_iiX_isw_iN_i	new_theta	new_sigmas                       r$   r_   GaussianNB._partial_fit  s=   :  DM24A
Ta:$0BM **RVVAA->-B-B-DD JDMM*I((I#:;DK)!89DI ""** ED {{&DKK0v;)+$%UVVzz&**,44$%IJJQJ##%%$%CDD$*! %'HHS-?rzz$R!wwqzT[[..q11N 
DKK4E4Ea4H'I!IJJIIadOt}},O--99Q< ggh8vv)**017< 
 C$$S)AHaK.C($#X.hhjiil#'#=#=!!!$dkk!Q$&71a4#t$ Iy !*DKK1'DIIadOa C' # & 			!Q$4==( ;; $ 1 1D4E4E4I4I4K KDr(   c                 H   / n[        [        R                  " U R                  5      5       H  n[        R                  " U R
                  U   5      nS[        R                  " [        R                  " S[        R                  -  U R                  US S 24   -  5      5      -  nUS[        R                  " XR                  US S 24   -
  S-  U R                  US S 24   -  S5      -  -  nUR                  XE-   5        M     [        R                  " U5      R                  nU$ )Ng      g       @g      ?rl   r   )ranger3   sizer2   logr   ro   pir   r   appendarrayr;   )r"   r#   joint_log_likelihoodr   jointin_ijs         r$   r%    GaussianNB._joint_log_likelihood  s    !rwwt}}-.AVVD--a01F"&&beedii1o(E!FGGDC"&&1{{1a4'8#8Q">499QPQT?!SUVWWWD ''6	 /  "xx(<=??##r(   )r   r   r2   r   rQ   r   r   rR   rU   NN)NFN)rC   rD   rE   rF   rG   r   r   rS   dict__annotations__rV   r   ra   r*   staticmethodr   r   r_   r%   rH   r    r(   r$   r   r      s    Nb  &"4D@A$D 
 "&T + 5
 6
83 G# G#R 5*
 6*
Xrh	$r(   r   c                      ^  \ rS rSr% Sr\" \SSSS9S/S/SS/S/S	.r\\	S
'   SS jr
\S 5       r\S 5       rS rSS jrSS jrS r\" SS9SS j5       r\" SS9SS j5       rS rU 4S jrSrU =r$ )_BaseDiscreteNBi	  zAbstract 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   NrM   rN   rL   booleanalpha	fit_priorclass_priorforce_alpharS   Tc                 4    Xl         X l        X0l        X@l        g rU   r   )r"   r   r   r   r   s        r$   rV   _BaseDiscreteNB.__init__  s    
"&&r(   c                     g)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$   _count_BaseDiscreteNB._count!  r'   r(   c                     g)zUpdate 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_prob(_BaseDiscreteNB._update_feature_log_prob2  r'   r(   c                     [        XSSS9$ )rd   csrFaccept_sparserf   rg   r!   s     r$   r*   _BaseDiscreteNB._check_X?  s    TEGGr(   c                     [        XUSUS9$ )z Validate X and y in fit methods.r   r   rg   r"   r#   r[   rf   s       r$   
_check_X_y_BaseDiscreteNB._check_X_yC  s    TauEJJr(   c                 f   [        U R                  5      nUb6  [        U5      U:w  a  [        S5      e[        R                  " U5      U l        gU R                  (       a  [        R                  " 5          [        R                  " S[        5        [        R                  " U R                  5      nSSS5        W[        R                  " U R                  R                  5       5      -
  U l        g[        R                  " U[        R                  " U5      * 5      U l        g! , (       d  f       Nw= f)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.
Nr   ignore)r   r2   r   r3   r   class_log_prior_r   warningscatch_warningssimplefilterRuntimeWarningr   ro   full)r"   r   r   log_class_counts       r$   _update_class_log_prior'_BaseDiscreteNB._update_class_log_priorG  s     &	";9, !QRR$&FF;$7D!^^((* %%h?"$&&):):";	 + %4bffT=N=N=R=R=T6U$UD!$&GGIy8I7I$JD! +*s   5<D""
D0c                 F   [        U R                  [        5      (       d   [        R                  " U R                  5      OU R                  n[        R
                  " U5      n[        U[        R                  5      (       aW  UR                  S   U R                  :X  d)  [        SUR                  S    SU R                   S35      eUS:  a  [        S5      eSnX#:  aB  U R                  (       d1  [        R                  " SUS S	35        [        R                  " X5      $ U$ )
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   r3   r   minndarrayrm   n_features_in_r   r   r   warnmaximum)r"   r   	alpha_minalpha_lower_bounds       r$   _check_alpha_BaseDiscreteNB._check_alpha_  s    *4TZZ*F*FBJJtzz"DJJ 	 FF5M	eRZZ((;;q>T%8%88  ;;q>**?@S@S?TTUW 
 1} !NOO!(1A1AMM%c* +
 ::e77r(   rX   c                 p   [        U S5      (       + nU R                  XUS9u  pUR                  u  pg[        X5      (       a  [	        U5      nU R                  X5        [        X R                  S9n	U	R                  S   S:X  aJ  [	        U R                  5      S:X  a  [        R                  " SU	-
  U	4SS9n	O[        R                  " U	5      n	UR                  S   U	R                  S   :w  a+  Sn
[        XR                  S   UR                  S   4-  5      eU	R                  [        R                  S	S
9n	Ub/  [        XA5      n[        R                  " U5      nXR                   -  n	U R"                  nU R%                  X5        U R'                  5       nU R)                  U5        U R+                  US9  U $ )aw  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.
r2   re   )r   r   rl   r0   r   z1X.shape[0]=%d and y.shape[0]=%d are incompatible.Fcopyr   )hasattrr   rm   r   r   _init_countersr   r2   r3   concatenate	ones_liker   astyper   r   r:   r;   r   r   r   r   r   )r"   r#   r[   r   r^   r   _r   r   r   r   r   r   s                r$   r   _BaseDiscreteNB.partial_fitw  sy   L !z22
q:6(77 GI	61mm4771:?4==!Q&NNAE1:A6LLO771:#ECSGGAJ
#;;<< HHRZZeH,$0BMMM-8M A&& 	A !!#%%e,$$$=r(   c                    U R                  X5      u  pUR                  u  pE[        5       nUR                  U5      nUR                  U l        UR                  S   S:X  aJ  [        U R                  5      S:X  a  [        R                  " SU-
  U4SS9nO[        R                  " U5      nUbM  UR                  [        R                  SS9n[        X15      n[        R                  " U5      nXsR                  -  nU R                  nUR                  S   n	U R                  X5        U R!                  X5        U R#                  5       n
U R%                  U
5        U R'                  US9  U $ )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   rl   r0   Fr   r   )r   rm   r   fit_transformr2   r   r3   r   r   r   r   r   r:   r;   r   r   r   r   r   r   )r"   r#   r[   r^   r   r   labelbinr   r   r   r   s              r$   ra   _BaseDiscreteNB.fit  s1   * q$!#""1% ))771:?4==!Q&NNAE1:A6LLO
 $%0A0BMMM-8M A&& GGAJ	I2A!!#%%e,$$$=r(   c                     [         R                  " U[         R                  S9U l        [         R                  " X4[         R                  S9U l        g )Nr   )r3   r   r   r   feature_count_)r"   r   r   s      r$   r   _BaseDiscreteNB._init_counters   s3    HHYbjjA hh	'>bjjQr(   c                 h   > [         TU ]  5       nSUR                  l        SUR                  l        U$ NT)super__sklearn_tags__
input_tagssparseclassifier_tags
poor_scorer"   tags	__class__s     r$   r    _BaseDiscreteNB.__sklearn_tags__  s/    w')!%*.'r(   )r   r   r   r   r2   r   r   r   )r   TNTTrU   r   )rC   rD   rE   rF   rG   r   r   rS   r   r   rV   r   r   r   r*   r   r   r   r   r   ra   r   r   rH   __classcell__r  s   @r$   r   r   	  s     4D8,G[$d+!{	$D '    
 
HKK00 5P 6Pd 53 63jR r(   r   c                   X   ^  \ rS rSrSrSSSSS.U 4S jjrU 4S jrS	 rS
 rS r	Sr
U =r$ )r   i  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]
r   TNr   r   r   r   c                &   > [         TU ]  UUUUS9  g Nr   )r   rV   )r"   r   r   r   r   r  s        r$   rV   MultinomialNB.__init__h  s#     	##	 	 	
r(   c                 F   > [         TU ]  5       nSUR                  l        U$ r   r   r   r   positive_onlyr  s     r$   r   MultinomialNB.__sklearn_tags__r  !    w')(,%r(   c                     [        US5        U =R                  [        UR                  U5      -  sl        U =R                  UR                  SS9-  sl        g)%Count and smooth feature occurrences.zMultinomialNB (input X)r   r0   N)r   r   r   r;   r   ro   r   s      r$   r   MultinomialNB._countw  sD    178qssA66QUUU]*r(   c                     U R                   U-   nUR                  SS9n[        R                  " U5      [        R                  " UR	                  SS5      5      -
  U l        g)=Apply smoothing to raw counts and recompute log probabilitiesr   r0   N)r   ro   r3   r   reshapefeature_log_prob_r"   r   smoothed_fcsmoothed_ccs       r$   r   &MultinomialNB._update_feature_log_prob}  sS    ))E1!oo1o-!#!4rvvA&8
 "
r(   c                 Z    [        XR                  R                  5      U R                  -   $ )8Calculate the posterior log probability of the samples X)r   r  r;   r   r!   s     r$   r%   #MultinomialNB._joint_log_likelihood  s$    q"8"8":":;d>S>SSSr(   )r  )rC   rD   rE   rF   rG   rV   r   r   r   r%   rH   r  r  s   @r$   r   r     s:    Zz $
 

+
T Tr(   r   c                      ^  \ rS rSr% Sr0 \R                  ESS/0Er\\S'   SSSSS	S
.U 4S jjr	U 4S jr
S rS rS rSrU =r$ )r   i  a&  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   rS   r   TNF)r   r   r   r   r#  c                2   > [         TU ]  UUUUS9  XPl        g Nr
  )r   rV   r#  )r"   r   r   r   r   r#  r  s         r$   rV   ComplementNB.__init__  s*     	##	 	 	
 	r(   c                 F   > [         TU ]  5       nSUR                  l        U$ r   r  r  s     r$   r   ComplementNB.__sklearn_tags__  r  r(   c                     [        US5        U =R                  [        UR                  U5      -  sl        U =R                  UR                  SS9-  sl        U R                  R                  SS9U l        g)zCount feature occurrences.zComplementNB (input X)r   r0   N)r   r   r   r;   r   ro   feature_all_r   s      r$   r   ComplementNB._count  s`    167qssA66QUUU]* //333;r(   c                     U R                   U-   U R                  -
  n[        R                  " X"R	                  SSS9-  5      nU R
                  (       a  UR	                  SSS9nX4-  nOU* nXPl        g)z6Apply smoothing to raw counts and compute the weights.r   T)r1   keepdimsN)r*  r   r3   r   ro   r#  r  )r"   r   
comp_countloggedsummedfeature_log_probs         r$   r   %ComplementNB._update_feature_log_prob  sj    &&.1D1DD

^^T^%JJK99ZZQZ6F% &w!1r(   c                     [        XR                  R                  5      n[        U R                  5      S:X  a  X R
                  -  nU$ )z0Calculate the class scores for the samples in X.r   )r   r  r;   r   r2   r   r5   s      r$   r%   "ComplementNB._joint_log_likelihood  s<    a!7!7!9!9:t}}"(((C
r(   )r*  r  r#  )rC   rD   rE   rF   rG   r   rS   r   r   rV   r   r   r   r%   rH   r  r  s   @r$   r   r     sg    bH$

0
0$$D   "
<
2 r(   r   c            
          ^  \ rS rSr% Sr0 \R                  ESS\" \SSSS9/0Er\	\
S'   S	S
SS
SS.U 4S jjrU 4S jrSU 4S jjrS rS rS rSrU =r$ )r   i&  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   rM   rN   rS   r   Trj   )r   r   r   r   r   c                2   > [         TU ]  UUUUS9  X0l        g r  )r   rV   r   )r"   r   r   r   r   r   r  s         r$   rV   BernoulliNB.__init__  s*     	##	 	 	
 !r(   c                 f   > [         TU ]  U5      nU R                  b  [        XR                  S9nU$ )rd   	threshold)r   r*   r   )r"   r#   r  s     r$   r*   BernoulliNB._check_X  s/    GQ==$mm4Ar(   c                 j   > [         TU ]  XUS9u  pU R                  b  [        XR                  S9nX4$ )Nre   r9  )r   r   r   )r"   r#   r[   rf   r  s       r$   r   BernoulliNB._check_X_y  s8    w!!e!4==$mm4Atr(   c                     U =R                   [        UR                  U5      -  sl         U =R                  UR	                  SS9-  sl        g)r  r   r0   N)r   r   r;   r   ro   r   s      r$   r   BernoulliNB._count  s9    qssA66QUUU]*r(   c                     U R                   U-   nU R                  US-  -   n[        R                  " U5      [        R                  " UR	                  SS5      5      -
  U l        g)r  rl   r  r   N)r   r   r3   r   r  r  r  s       r$   r   $BernoulliNB._update_feature_log_prob  sW    ))E1''%!)3!#!4rvvA&8
 "
r(   c                 l   U R                   R                  S   nUR                  S   nX2:w  a  [        SX#4-  5      e[        R                  " S[        R
                  " U R                   5      -
  5      n[        XR                   U-
  R                  5      nXPR                  UR                  SS9-   -  nU$ )r   r   z/Expected input with %d features, got %d insteadr0   )
r  rm   r   r3   r   r@   r   r;   r   ro   )r"   r#   r   n_features_Xneg_probr6   s         r$   r%   !BernoulliNB._joint_log_likelihood  s    ++11!4
wwqz%A,- 
 66!bffT%;%;<<=a"8"88"C!F!FG$$x|||';;;
r(   )r   r  r  )rC   rD   rE   rF   rG   r   rS   r   r   r   r   rV   r*   r   r   r   r%   rH   r  r  s   @r$   r   r   &  sz    cJ$

0
0$T8D!T&AB$D  ! !"+

 r(   r   c            
          ^  \ rS rSr% Sr0 \R                  ESS\" \SSSS9/\" \	SSSS9/S	.Er\
\S
'   SSSSSS.U 4S jjrSU 4S jjrSU 4S jjrU 4S jrS rSS jrS r\S 5       rS rS rS rSrU =r$ )r   i  a  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]
NrL   r   rM   rN   r   )min_categoriesr   rS   r   T)r   r   r   r   rG  c                2   > [         TU ]  UUUUS9  XPl        g r%  )r   rV   rG  )r"   r   r   r   r   rG  r  s         r$   rV   CategoricalNB.__init__B  s+     	##	 	 	
 -r(   c                     > [         TU ]  XUS9$ )aL  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.
r^   )r   ra   )r"   r#   r[   r^   r  s       r$   ra   CategoricalNB.fitS  s    2 w{1}{==r(   c                     > [         TU ]  XX4S9$ )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.
rK  )r   r   )r"   r#   r[   r   r^   r  s        r$   r   CategoricalNB.partial_fitn  s    T w"1"NNr(   c                    > [         TU ]  5       nSUR                  l        SUR                  l        SUR                  l        U$ )NTF)r   r   r   categoricalr   r  r  s     r$   r   CategoricalNB.__sklearn_tags__  s9    w')&*#!&(,%r(   c           	      :    [        U USSSSS9n[        US5        U$ )rd   intFTr   r   ensure_all_finiterf   CategoricalNB (input X)r   r   r!   s     r$   r*   CategoricalNB._check_X  s0    "
 	178r(   c           
      B    [        U UUSSSUS9u  p[        US5        X4$ )NrS  FTrT  rV  rW  r   s       r$   r   CategoricalNB._check_X_y  s7    "
 	178tr(   c                     [         R                  " U[         R                  S9U l        [	        U5       Vs/ s H  n[         R                  " US45      PM     snU l        g s  snf )Nr   r   )r3   r   r   r   r   category_count_)r"   r   r   r   s       r$   r   CategoricalNB._init_counters  sG    HHYbjjABG
BSTBSQ)Q 8BSTTs   "A!c                    U R                  SS9S-   n[        R                  " U5      nUb  [        R                  " UR                  [        R
                  5      (       d  [        SUR                   S35      e[        R                  " X#[        R                  S9nUR                  UR                  :w  a)  [        SU R                  S    SUR                   S35      eU$ U$ )	Nr   r0   r   z0'min_categories' should have integral type. Got z	 instead.r   z$'min_categories' should have shape (z',) when an array-like is provided. Got )
r   r3   r   
issubdtyper   signedintegerr   r   int64rm   )r#   rG  n_categories_Xmin_categories_n_categories_s        r$   _validate_n_categories$CategoricalNB._validate_n_categories  s     A*((>2%==!6!68H8HII F&,,-Y8  JJ~bhhWM""n&:&:: :1771:, G'--.i9 
 ! !!r(   c                    S nS nU =R                   UR                  SS9-  sl         U R                  XR                  5      U l        [        U R                  5       Hm  nUS S 2U4   nU" U R                  U   U R                  U   S-
  5      U R                  U'   U" XbU R                  U   U R                   R                  S   5        Mo     g )Nc                 t    US-   U R                   S   -
  nUS:  a  [        R                  " U SSU4/S5      $ U $ )Nr   r   )r   r   constant)rm   r3   pad)	cat_counthighest_featurediffs      r$   _update_cat_count_dims4CategoricalNB._count.<locals>._update_cat_count_dims  sC    "Q&);;Daxvvi&1d))<jIIr(   c                 B   [        U5       H  nUS S 2U4   R                  [        5      nUR                  R                  [
        R                  :X  a  S nOXU4   n[
        R                  " X   US9n[
        R                  " U5      S   nX$U4==   Xx   -  ss'   M     g )N)rk   r   )	r   r   boolr   typer3   ra  bincountnonzero)		X_featurer   rk  r   jmaskrk   countsindicess	            r$   _update_cat_count/CategoricalNB._count.<locals>._update_cat_count  s    9%Aw~~d+77<<288+"GajGY_gF**V,Q/W*%8% &r(   r   r0   r   )	r   ro   re  rG  rd  r   r   r\  rm   )r"   r#   r   rn  rz  r   ru  s          r$   r   CategoricalNB._count  s    			9 	QUUU]*!88<O<OPt**+A!Q$I&<$$Q'););A)>)B'D  # d2215t7H7H7N7Nq7Q ,r(   c           
      &   / n[        U R                  5       Hp  nU R                  U   U-   nUR                  SS9nUR	                  [
        R                  " U5      [
        R                  " UR                  SS5      5      -
  5        Mr     X l        g )Nr   r0   r  )	r   r   r\  ro   r   r3   r   r  r  )r"   r   r1  r   smoothed_cat_countsmoothed_class_counts         r$   r   &CategoricalNB._update_feature_log_prob  s    t**+A!%!5!5a!85!@#5#9#9q#9#A ##)*RVV4H4P4PQSUV4W-XX , "2r(   c                 <   [        XSS9  [        R                  " UR                  S   U R                  R                  S   45      n[        U R                  5       H.  nUS S 2U4   nX R                  U   S S 2U4   R                  -  nM0     X R                  -   nU$ )NFre   r   )
r   r3   r   rm   r   r   r   r  r;   r   )r"   r#   r6   r   ry  total_lls         r$   r%   #CategoricalNB._joint_log_likelihood  s    $/hh
D$5$5$;$;A$>?@t**+A1gG))!,QZ8:::C , ...r(   )r\  r   r  rG  rd  rU   r   r  )rC   rD   rE   rF   rG   r   rS   r   r   r   r   r   rV   ra   r   r   r*   r   r   r   re  r   r   r%   rH   r  r  s   @r$   r   r     s    eN$

0
0$ Xq$v6

 4D89$D  - -">6*OXU " "*<2 r(   r   )(rG   r   abcr   r   numbersr   r   numpyr3   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>r     s     ' "  # 
 D C - * ; i1o} i1Xo$ o$dg D}TO }T@X? Xvg/ gTtO tr(   