Naive Bayes Classifier
Hard
machine-learning
Meta
OpenAI
Implement a simple Naive Bayes text classifier. Given training data as a list of (text, label) tuples, build a model and predict the label for a new text. Use word counts (bag of words) and Laplace smoothing.
Example
train = [("good great awesome", "pos"), ("bad terrible awful", "neg"), ("good awesome", "pos")]
predict = naive_bayes_predict(train, "good")
# => "pos"
Test Cases
Python Editor
Output
Click "Run" to see results...