Skip to content

[MRG] Fix math syntax for ComplementNB documentation. #9644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions doc/modules/naive_bayes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ while :math:`\alpha < 1` is called Lidstone smoothing.
.. _complement_naive_bayes:

Complement Naive Bayes
-----------------------
----------------------

:class:`ComplementNB` implements the complement naive Bayes (CNB) algorithm.
CNB is an adaptation of the standard multinomial naive Bayes (MNB) algorithm
Expand All @@ -149,20 +149,23 @@ calculating the weights is as follows:

.. math::

\hat{\theta}_{ci} = \frac{\sum{j:y_j \neq c} d_{ij} + \alpha_i}
{\sum{j:y_j \neq c} \sum{k} d_{kj} + \alpha}
\hat{\theta}_{ci} = \frac{\alpha_i + \sum_{j:y_j \neq c} d_{ij}}
{\alpha + \sum_{j:y_j \neq c} \sum_{k} d_{kj}}

w_{ci} = \log \hat{\theta}_{ci}
w_{ci} = \frac{w_{ci}{\sum{j} w_{cj}}

where the summation is over all documents :math:`j` not in class :math:`c`,
w_{ci} = \frac{w_{ci}}{\sum_{j} w_{cj}}

where the summations are over all documents :math:`j` not in class :math:`c`,
:math:`d_{ij}` is either the count or tf-idf value of term :math:`i` in document
:math:`j`, and :math:`\alpha` is a smoothing hyperparameter like that found in
MNB. The second normalization addresses the tendency for longer documents to
dominate parameter estimates in MNB. The classification rule is:
:math:`j`, :math:`\alpha_i` is a smoothing hyperparameter like that found in
MNB, and :math:`\alpha = \sum_{i} \alpha_i`. The second normalization addresses
the tendency for longer documents to dominate parameter estimates in MNB. The
classification rule is:

.. math::

\hat{c} = \arg\min_c \sum{i} t_i w_{ci}
\hat{c} = \arg\min_c \sum_{i} t_i w_{ci}

i.e., a document is assigned to the class that is the *poorest* complement
match.
Expand Down