473,418 Members | 2,085 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Help with Sentiment Analysis code is required - unexpected outcome!

BarryA
19 16bit
Hello everyone,

I'm hoping you can help me with a difficulty I'm having with my Sentiment Analysis project. I've been attempting to apply a simple sentiment analysis model to a dataset of movie reviews, but I'm getting some surprising results. Here's the pertinent section of my code:
Expand|Select|Wrap|Line Numbers
  1. import pandas as pd
  2. from sklearn.model_selection import train_test_split
  3. from sklearn.feature_extraction.text import CountVectorizer
  4. from sklearn.linear_model import LogisticRegression
  5.  
  6. # Load the movie reviews dataset
  7. data = pd.read_csv('movie_reviews.csv')
  8.  
  9. # Preprocess the data
  10. # ... (code for data preprocessing)
  11.  
  12. # Split the dataset into training and testing sets
  13. X_train, X_test, y_train, y_test = train_test_split(data['review'], data['sentiment'], test_size=0.2, random_state=42)
  14.  
  15. # Vectorize the text data using CountVectorizer
  16. vectorizer = CountVectorizer()
  17. X_train_vectorized = vectorizer.fit_transform(X_train)
  18. X_test_vectorized = vectorizer.transform(X_test)
  19.  
  20. # Train the Logistic Regression model
  21. model = LogisticRegression()
  22. model.fit(X_train_vectorized, y_train)
  23.  
  24. # Evaluate the model
  25. accuracy = model.score(X_test_vectorized, y_test)
  26. print(f"Accuracy: {accuracy}")
  27.  
When I run the code, the accuracy is constantly around 50%, which is dangerously similar to random guessing. I assume there's a problem with how I'm vectorizing the text input or training the model, but I can't figure out what's causing this problem.

I verified the dataset and read more about it in this article, and it appears to be successfully loaded with both'review' and'sentiment' columns. I also attempted a simple Naive Bayes classifier, but it didn't help much in accuracy.

Could you kindly evaluate the code and let me know if you find any flaws or improvements that may help me enhance the accuracy of my sentiment analysis model?

Thank you in advance for your help!
Jul 25 '23 #1
0 13707

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Hugh Haggerty | last post by:
I need help with VB6 code to direct a WAV file to the computer speaker. Anyone know how to do this?
2
by: phangmo | last post by:
Hi, I write a C# to get information from a XML site, when I run my program at home, there's no problem. But when in office, I've got this error: ----------------------- Unhandled Exception:...
1
by: Rob Meade | last post by:
Hi all, I found an article on how to write a Windows service here: http://www.dotnetbips.com/displayarticle.aspx?id=178 It was pretty much what I wanted, I want the service to scan a...
6
by: TC | last post by:
Hi. I write a program in c language that read a text file and extrapolate the word. for all word the program calculate the number of the times that word is present in the text. The problem is the...
9
by: psantosh12 | last post by:
Hello everyone I need help to develop code for bug tracking system by using servlet and jsp technologies.. If anybody having code please send me the code. Regards Santosh
4
by: psycho007 | last post by:
Hi I have a caller ID software that I would like to change from Microsoft Access database to Mysql and was wondering if somebody could help me. The code i currently have is: Private Sub...
1
by: matan9234 | last post by:
hi, I need help in fitting code of buttons of website to all browsers (right now the code works only for explorer), can you tell me what i need to add to the code for the option of chrome/fire fox...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.