ValueError Found input variables with inconsistent numbers of samples 2 515738

0 votes

Hi guys, first I wanted to say that this is my first time trying this. Secondly. I'm not sure I'm placing this question at the right forum. If it's not, please excuse me. 

I'm trying to use Naive Bayes on my data. This is my code till now:

data = pd.read_json('/Users/rokayadarai/Desktop/Coding/DataSets/Hotel_Reviews.json')
data.head()
#stopword are not useful words (like: a, and, the)
stopset = set(stopwords.words('english'))
vectorizer = TfidfVectorizer(use_idf=True, lowercase=True, strip_accents='ascii', stop_words=stopset)
y = data["Reviewer_Score"]
x = vectorizer.fit_transform(['Ngative_Review', 'Positive_Review'])
#515738 observations and 2(?) unique words
print (y.shape)
print (x.shape)
#split the data - 0.2 means 20% of the data. 123 means use same dataset with every test
x_train, x_test, y_train, y_test = train_test_split(x,y,test_size=0.2,random_state=123)

When I try to run this, I get the error: ValueError: Found input variables with inconsistent numbers of samples: [2, 515738]. Could please somebody helps me out? I'm stuck and can't seem to find anything on the Internet to help me. 

Dec 15, 2020 in Machine Learning by anonymous
• 170 points

edited Dec 15, 2020 by MD 3,815 views

1 answer to this question.

0 votes

Hi,

You are asking your query in the right place. You might get the above error because of the shape of x and y. So check the shape of x and if it is 1D, then convert it from 1D to 2D.

answered Dec 15, 2020 by MD
• 95,460 points

Related Questions In Machine Learning

0 votes
0 answers

ValueError: Found input variables with inconsistent numbers of samples: [11, 3988]

After reshaping also I am getting the ...READ MORE

Aug 27, 2020 in Machine Learning by sairam
• 160 points

edited Aug 27, 2020 by MD 5,310 views
0 votes
1 answer

ValueError: Found input variables with inconsistent numbers of samples: [616, 308]

Hi@Alshwarya, I think there is a problem with your ...READ MORE

answered Sep 23, 2020 in Machine Learning by MD
• 95,460 points
4,286 views
0 votes
1 answer

Found input variables with inconsistent numbers of samples:

Hi@sagar, You have converted your Dataframe into an ...READ MORE

answered Jul 13, 2020 in Machine Learning by MD
• 95,460 points
5,306 views
0 votes
1 answer

problem with Found input variables with inconsistent numbers of samples: [1204, 134]

Hi@Alessandro, Here you used x as your feature parameter ...READ MORE

answered Jul 20, 2020 in Machine Learning by MD
• 95,460 points
5,148 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,442 views
0 votes
1 answer
0 votes
1 answer

Purpose of fit method in sklearn module in python?

it basically trains your model using the ...READ MORE

answered May 14, 2020 in Python by Mahesh
• 140 points
3,552 views
+1 vote
2 answers

ValueError: Found input variables with inconsistent numbers of samples: [1, 1000]

Hi@akhtar, Here you used x as your feature ...READ MORE

answered Apr 14, 2020 in Machine Learning by MD
• 95,460 points

edited Aug 11, 2021 by Soumya 57,920 views
0 votes
2 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP