到情感分析分类:我们训练了各种机器学习模型和深度神经网络,将评论文本的情感分类为3个主要类别(积极,中性,消极)。
# TfidfVectorizer transform train and test
con_vec = TfidfVectorizer(stop_words='english',tokenizer=tokenize,max_features=20000,ngram_range=(1,2))
X_train_tfidf = con_vec.fit_transform(X_train)
# with open("tfidf_vectorizer.pkl", 'wb') as handle:
# pickle.dump(con_vec, handle)
y_train_tfidf = y_train
X_test_tfidf = con_vec.transform(X_test)
y_test_tfidf = y_test
**ERROR CODE :**
**Pandas Version is pandas 1.1.4**
---------------------------------------------------------------------------
1 from nltk import word_tokenize # Generate table of words with their counts
2 from nltk.tokenize import word_tokenize # TfidfVectorizer transform train and test
----> 3 con_vec = TfidfVectorizer(stop_words='english',tokenizer=tokenize,max_features=20000,ngram_range=(1,2))
4 X_train_tfidf = con_vec.fit_transform(X_train)
**NameError: name 'tokenize' is not defined**
Any solution how to remove this error?
Also tried from **nltk import word_tokenize** but still same error
[1]: https://i.stack.imgur.com/lmoSp.png发布于 2020-12-01 03:44:40
尝试导入它:
from nltk.tokenize import tokenizehttps://stackoverflow.com/questions/65080117
复制相似问题