Skip to content

GaussianNB

Gaussian Naive Bayes.

A Gaussian distribution \(G_{cf}\) is maintained for each class \(c\) and each feature \(f\). Each Gaussian is updated using the amount associated with each feature; the details can be be found in proba.Gaussian. The joint log-likelihood is then obtained by summing the log probabilities of each feature associated with each class.

Examples

from river import naive_bayes
from river import stream
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])

model = naive_bayes.GaussianNB()

for x, y in stream.iter_array(X, Y):
    _ = model.learn_one(x, y)

model.predict_one({0: -0.8, 1: -1})
1

Methods

joint_log_likelihood
joint_log_likelihood_many
learn_one

Update the model with a set of features x and a label y.

Parameters

  • x'dict'
  • y'base.typing.ClfTarget'

Returns

Classifier: self

p_class
predict_one

Predict the label of a set of features x.

Parameters

  • x'dict'
  • kwargs

Returns

base.typing.ClfTarget | None: The predicted label.

predict_proba_one

Return probabilities using the log-likelihoods.

Parameters

  • x'dict'