Python Forum
I am getting ValueError from running my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I am getting ValueError from running my code
#1
I am doing a project on Twitter tweet sentiment analysis following a project on a blog (link at the bottom), and I am getting the following error when running the code on Google Colab:
ValueError: Found input variables with inconsistent numbers of samples: [2, 41157]

Here are the procedures I have gone through:
First I read a CSV file with 41,157 tweets as training data.
Then, I ran a regular expression function to remove any symbols and special characters to get pure data
I converted the text into the matrix of tokens

I get the error when running the following:

(LabelEncoder is used here for transforming categorical values into numerical values.)

X_train = vectoriser.fit_transform(df["CleanedTweet"])
# Encoding the classes in numerical values
from sklearn.preprocessing import LabelEncoder
encoder = LabelEncoder()
y_train = encoder.fit_transform(df['Sentiment'])
from sklearn.naive_bayes import MultinomialNB
classifier = MultinomialNB()
classifier.fit(X_train, y_train)
Can someone tell me what might have gone wrong? Help would be appreciated!
Here is the URL to the project I am learning from: https://www.analyticsvidhya.com/blog/202...th-python/
Larz60+ write Dec-26-2021, 09:39 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code not running even without errors Azdaghost 2 229 Apr-25-2025, 07:35 PM
Last Post: Azdaghost
  python code not running Azdaghost 1 215 Apr-22-2025, 08:44 PM
Last Post: deanhystad
  writing and running code in vscode without saving it akbarza 5 2,425 Mar-03-2025, 08:14 PM
Last Post: Gribouillis
  problem in running a code akbarza 7 2,366 Feb-14-2024, 02:57 PM
Last Post: snippsat
  the order of running code in a decorator function akbarza 2 1,363 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Code running many times nad not just one? korenron 4 2,228 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 6,776 Jul-01-2022, 02:51 PM
Last Post: maiya
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 2,420 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Why is this Python code running twice? mcva 5 7,197 Feb-02-2022, 10:21 AM
Last Post: mcva
  Python keeps running the old version of the code quest 2 6,254 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020