input: Write a python function to implement a Naive Bayes classifier to train and predict labels for a given dataset.
  assert nb_classifier.predict(['I love programming']) == ['positive']
  assert nb_classifier.predict(['I hate bugs']) == ['negative']
  assert nb_classifier.predict(['Python is great']) == ['positive']
output: from collections import defaultdict
  import math
  
  class NaiveBayesClassifier:
      def __init__(self):
          self.classes = defaultdict(int)
          self.word_freq = defaultdict(lambda: defaultdict(int))
          self.class_freq = defaultdict(int)
          self.total_docs = 0
  
      def train(self, X, y):
          self.total_docs = len(y)
          for doc, label in zip(X, y):
              self.classes[label] += 1
              self.class_freq[label] += 1
              for word in doc.split():
                  self.word_freq[label][word] += 1
                  self.class_freq[label] += 1
  
      def predict(self, X):
          predictions = []
          for doc in X:
              class_probs = {}
              for cls in self.classes:
                  class_probs[cls] = math.log(self.classes[cls] / self.total_docs)
                  for word in doc.split():
                      word_prob = (self.word_freq[cls][word] + 1) / (self.class_freq[cls] + len(self.word_freq[cls]))
                      class_probs[cls] += math.log(word_prob)
              predictions.append(max(class_probs, key=class_probs.get))
          return predictions
  
  nb_classifier = NaiveBayesClassifier()
  nb_classifier.train(['I love programming', 'I hate bugs', 'Python is great'], ['positive', 'negative', 'positive'])