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. The dataset can be downloaded from https://www.kaggle.com/jiashenliu/515k-hotel-reviews-data-in-europe. 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(['Negative_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 332 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,060 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 1,293 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,060 points
356 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,060 points
2,313 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,060 points
1,482 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 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,858 views
0 votes
0 answers
0 votes
1 answer

Purpose of fit method in sklearn module in python?

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

answered May 13, 2020 in Python by Mahesh
• 140 points
1,576 views
+1 vote
1 answer
0 votes
2 answers