<commit_before># -*- coding: utf-8 -*-

"""
Naive Bayes models
==================

Naive Bayes algorithms are a set of supervised learning methods based on
applying Bayes' theorem with strong (naive) feature independence assumptions.

See http://scikit-learn.sourceforge.net/modules/naive_bayes.html for
complete documentation.
"""

# Author: <NAME> <<EMAIL>>
#         Minor fixes by <NAME>
#         <NAME> <<EMAIL>>
#         <NAME> <<EMAIL>>
#         <NAME> <<EMAIL>>
#         (parts based on earlier work by <NAME>)
#
# License: BSD Style.

import numpy as np
from scipy.sparse import issparse

from .base import BaseEstimator, ClassifierMixin
from .preprocessing import binarize, LabelBinarizer
from .utils import array2d, atleast2d_or_csr, safe_asarray
from .utils.extmath import safe_sparse_dot, logsum
from .utils.fixes import unique



class BaseNB(BaseEstimator, ClassifierMixin):
    """Abstract base class for naive Bayes estimators

    Any estimator based on this class should provide:

    __init__
    fit(X, y)
    _joint_log_likelihood(X)
        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_classes, n_samples].

    Input is passed to _joint_log_likelihood as is by predict, predict_proba
    and predict_log_proba.
    """

    def predict(self, X):
        """
        Perform classification on an array of test vectors X.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]

        Returns
        -------
        C : array, shape = [n_samples]
            Predicted target values for X
        """
        jll = self._joint_log_likelihood(X)
        y_pred = self._classes[np.argmax(jll, axis=1)]
        return y_pred

    def predict_log_proba(self, X):
        """
        Return log-probability estimates for the test vector X.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]

        Returns
        -------
        C : array-like, shape = [n_samples, n_classes]
            Returns the log-probability of the sample for each class
            in the model, where classes are ordered arithmetically.
        """
        jll = self._joint_log_likelihood(X)
        # normalize by P(x) = P(f_1, ..., f_n)
        log_prob_x = logsum(jll, axis=1)
        return jll - np.atleast_2d(log_prob_x).T

    def predict_proba(self, X):
        """
        Return probability estimates for the test vector X.

        Parameters
        ----------<commit_msg>COSMIT in naive_bayes<commit_after># -*- coding: utf-8 -*-

"""
Naive Bayes models
==================

Naive Bayes algorithms are a set of supervised learning methods based on
applying Bayes' theorem with strong (naive) feature independence assumptions.

See http://scikit-learn.sourceforge.net/modules/naive_bayes.html for
complete documentation.
"""

# Author: <NAME> <<EMAIL>>
#         Minor fixes by <NAME>
#         <NAME> <<EMAIL>>
#         <NAME> <<EMAIL>>
#         <NAME> <<EMAIL>>
#         (parts based on earlier work by <NAME>)
#
# License: BSD Style.

import numpy as np
from scipy.sparse import issparse

from .base import BaseEstimator, ClassifierMixin
from .preprocessing import binarize, LabelBinarizer
from .utils import array2d, atleast2d_or_csr, safe_asarray
from .utils.extmath import safe_sparse_dot, logsum
from .utils.fixes import unique



class BaseNB(BaseEstimator, ClassifierMixin):
    """Abstract base class for naive Bayes estimators

    Any estimator based on this class should provide:

    __init__
    fit(X, y)
    _joint_log_likelihood(X)
        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_classes, n_samples].

    Input is passed to _joint_log_likelihood as is by predict, predict_proba
    and predict_log_proba.
    """

    def predict(self, X):
        """
        Perform classification on an array of test vectors X.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]

        Returns
        -------
        C : array, shape = [n_samples]
            Predicted target values for X
        """
        jll = self._joint_log_likelihood(X)
        return self._classes[np.argmax(jll, axis=1)]

    def predict_log_proba(self, X):
        """
        Return log-probability estimates for the test vector X.

        Parameters
        ----------
        X : array-like, shape = [n_samples, n_features]

        Returns
        -------
        C : array-like, shape = [n_samples, n_classes]
            Returns the log-probability of the sample for each class
            in the model, where classes are ordered arithmetically.
        """
        jll = self._joint_log_likelihood(X)
        # normalize by P(x) = P(f_1, ..., f_n)
        log_prob_x = logsum(jll, axis=1)
        return jll - np.atleast_2d(log_prob_x).T

    def predict_proba(self, X):
        """
        Return probability estimates for the test vector X.

        Parameters
        ----------
{'fraction_non_alphanumeric': 0.10845015576323988, 'fraction_numerical': 0.0027258566978193145, 'mean_word_length': 2.3270725388601035, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6575627', 'n_tokens_mistral': 1577, 'n_tokens_neox': 1520, 'n_words': 496}