To classify text sentiment using NLTK's Naive Bayes Classifier, you can prepare labeled data, extract features, train the classifier, and use it for prediction. Here is the code example which you can refer to:
In the above code, we are using the following key points:
- Data Preparation: Use the movie_reviews dataset, which has positive and negative labels.
- Feature Extraction: Convert words into a feature dictionary indicating their presence ({word: True}).
- Train/Test Split: Split the data into a training and testing set.
- Train Classifier: Use NaiveBayesClassifier.train() to train on the training set.
- Classify Text: Tokenize input text, extract features, and classify its sentiment.
Hence, the output will classify the example text as either pos (positive) or neg (negative).