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
  problem in running a code akbarza 7 642 Feb-14-2024, 02:57 PM
Last Post: snippsat
  writing and running code in vscode without saving it akbarza 1 385 Jan-11-2024, 02:59 PM
Last Post: deanhystad
  the order of running code in a decorator function akbarza 2 522 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Code running many times nad not just one? korenron 4 1,363 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 3,750 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 1,505 Apr-06-2022, 03:41 PM
Last Post: Gribouillis
  Why is this Python code running twice? mcva 5 5,283 Feb-02-2022, 10:21 AM
Last Post: mcva
  Python keeps running the old version of the code quest 2 3,765 Jan-20-2022, 07:34 AM
Last Post: ThiefOfTime
  My python code is running very slow on millions of records shantanu97 7 2,580 Dec-28-2021, 11:02 AM
Last Post: Larz60+
  rtmidi problem after running the code x times philipbergwerf 1 2,429 Apr-04-2021, 07:07 PM
Last Post: philipbergwerf

Forum Jump:

User Panel Messages

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