Implement the Naive Bayes algorithm