0

I am trying to run MultinomiaL Naive bayes and receiving the below error. Sample training data is given. Test data is exactly similar.

def main():
    text_train, targets_train = read_data('train')
    text_test, targets_test = read_data('test')
    classifier1 = MultinomialNB()
    classifier1.fit(text_train, targets_train)
    prediction1 = classifier1.predict(text_test)

Sample Data:

Train: 
category, text
Family, I love you Mom
University, I hate this course
ComplexData
  • 1,091
  • 4
  • 19
  • 36
  • what is the shape of your `text_train` and `targets_train`? Also I dont think MultinomialNB will handle text data by default. You need to preprocess it. – Vivek Kumar Feb 13 '17 at 05:19

1 Answers1

0

Sometimes I face this question and find most of reason from the error is the input data should be 2-D array, such as if you want to build a regression model. you write this code and then you will face this error!

for example:

a = np.array([1,2,3]).T
b = np.array([4,5,6]).T

regr = linear_model.LinearRegression()
regr.fit(a, b)

then you should add something!

a = np.array([[1,2,3]]).T
b = np.array([[4,5,6]]).T

lastly you will be run normally! so it is just my empirical! This is just a reference, not a standard answer! i am from Chinese as a student in learning English and python!

znb booker
  • 41
  • 1
  • 1
  • 2