<filename>Examples/multinomial_naive_bayes_example.py
from MLlib.models import MultinomialNB
import numpy as np


with open('datasets/multinomial_naive_bayes_dataset.txt', 'r') as f:
    words = [[string.strip('\n')
              for string in line.split(',')] for line in f]
for i in range(len(words)):
    words[i] = list(map(int, words[i]))

x = np.array([words[i] for i in range(len(words)-1)])
y_class = np.array(words[-1])

test = np.array([[0, 1, 1, 0, 1, 1], [1, 1, 1, 0, 0, 1]])
nb = MultinomialNB().fit(x, y_class)
print(nb.predict(test))

<filename>Examples/multinomial_naive_bayes_example.py
from MLlib.models import MultinomialNB
import numpy as np


with open('datasets/multinomial_naive_bayes_dataset.txt', 'r') as f:
    words = [[string.strip('\n')
              for string in line.split(',')] for line in f]
for i in range(len(words)):
    words[i] = list(map(int, words[i]))

x = np.array([words[i] for i in range(len(words)-1)])
y_class = np.array(words[-1])

test = np.array([[0, 1, 1, 0, 1, 1], [1, 1, 1, 0, 0, 1]])
nb = MultinomialNB().fit(x, y_class)
print(nb.predict(test))
