#EXP No :- 05
#AIM :- Implement Sentiment analysis on text dataset to evaluate
customer review.
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.naive_bayes import MultinomialNB
# Load the dataset
df = pd.read_csv('customer_reviews.csv')
print(df)
# Split the dataset into training and test sets
X_train = df[df.index % 2 == 0]['review'].values
X_test = df[df.index % 2 == 1]['review'].values
y_train = df[df.index % 2 == 0]['sentiment'].values
y_test = df[df.index % 2 == 1]['sentiment'].values
# Vectorize the text data
vectorizer = CountVectorizer(lowercase=True, stop_words='english')
X_train_vec = vectorizer.fit_transform(X_train)
X_test_vec = vectorizer.transform(X_test)
# Train a classifier
clf = MultinomialNB()
clf.fit(X_train_vec, y_train)
# Evaluate the classifier on the test set
accuracy = clf.score(X_test_vec, y_test)
print(f'Test accuracy: {accuracy:.2f}')
review sentiment
0 I love this product! It is so easy to use and ... positive
1 This product is a complete waste of money. It ... negative
2 I am happy with my purchase. The product does ... positive
3 I was disappointed with this product. It did n... negative
4 The product is okay. neutral
5 but there are better options available at a lo... neutral
Test accuracy: 0.00