0% found this document useful (0 votes)
9 views1 page

05 ML PDF

The document outlines the implementation of sentiment analysis on a customer review dataset using Python. It includes loading the dataset, splitting it into training and test sets, vectorizing the text data, training a Multinomial Naive Bayes classifier, and evaluating its accuracy. The final test accuracy reported is 0.00, indicating that the model did not perform well on the test data.

Uploaded by

Shraddha Ambekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

05 ML PDF

The document outlines the implementation of sentiment analysis on a customer review dataset using Python. It includes loading the dataset, splitting it into training and test sets, vectorizing the text data, training a Multinomial Naive Bayes classifier, and evaluating its accuracy. The final test accuracy reported is 0.00, indicating that the model did not perform well on the test data.

Uploaded by

Shraddha Ambekar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

#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

You might also like