Value Error: "empty vocabulary; perhaps the documents only contain stop words"

Viewed 17

from sklearn.feature_extraction.text import CountVectorizer

from sklearn.feature_extraction.text import TfidfTransformer

from sklearn.naive_bayes import MultinomialNB

from sklearn.ensemble import RandomForestClassifier

from sklearn.pipeline import Pipeline

text_clf = Pipeline([('vect', CountVectorizer()), ('tfidf', TfidfTransformer()),('clf', RandomForestClassifier(class_weight='balanced', n_estimators=100))])

text_clf.fit(tokenizer.sequences_to_texts_generator(train_text_vec), y_train.argmax(axis=1))

predictions = text_clf.predict(tokenizer.sequences_to_texts_generator(test_text_vec))

print('Baseline Accuracy Using Naive Bayes: ', (predictions == y_test.argmax(axis = 1)).mean())

print('F1 Score:', f1_score(y_test.argmax(axis = 1), predictions, average='weighted'))

conf = plot_confusion_matrix(y_test.argmax(axis = 1), predictions, classes=encoder. Classes_, title='Confusion matrix, without normalization')

1 Answers

Did you try ?

python -m ensurepip --default-pip

or

python -m pip install
Related