'Trying to train a MultinomialNB classifier with Bag Of Word technique

Hi every body I'm trying to train a Multinomial DB with BOW techinque. Here the code of BOW:

vectorizer = CountVectorizer()
X_train_bow = vectorizer.fit_transform(train_X)

#BOW model (Test Set) 
vectorizer = CountVectorizer()
X_test_bow = vectorizer.fit_transform(test_X)
print(X_test_bow)

Here my classifier code:

#MULTINOMIAL NAIVE BAYES CLASSIFIER + BOW
naive_bayes_classifier = MultinomialNB()
naive_bayes_classifier.fit(X_train_bow, train_y)
y_pred = naive_bayes_classifier.predict(X_test_bow)
print(metrics.classification_report(test_y, y_pred, target_names=['Bad', 'Neutral','Good']))

I obtain this error:

ValueError: X has 9601 features, but MultinomialNB is expecting 10972 features as input.

What am I doing wrong? Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source