Professional Documents
Culture Documents
I008 - Khemal Desai - PAI - Practical-9
I008 - Khemal Desai - PAI - Practical-9
Bag of Words
Code:
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# Training data
train_data = ['This is a positive text', 'This text is negative', 'This is a neutral text']
train_labels = np.array([1, 0, 2]) # 1 for positive, 0 for negative, 2 for neutral
# Test data
test_data = ['This is a positive test', 'This test is negative', 'This is a neutral test']
# Vectorize the test data using the same vectorizer as the training data
test_vectors = vectorizer.transform(test_data)
Output: