【发布时间】:2018-10-13 14:39:36
【问题描述】:
我不希望长度小于 3 或大于 7 的术语。在 R 中有一种直接的方法,但在 Python 中我不确定。 这个我试过了,还是不行
from sklearn.feature_extraction.text import CountVectorizer
regex1 = '/^[a-zA-Z]{3,7}$/'
vectorizer = CountVectorizer( analyzer='word',tokenizer= tokenize,stop_words = stopwords,token_pattern = regex1,min_df= 2, max_df = 0.9,max_features = 2000)
vectorizer1 = vectorizer.fit_transform(token_dict.values())
也尝试了其他正则表达式 -
"^[a-zA-Z]{3,7}$"
r'^[a-zA-Z]{3,7}$'
【问题讨论】:
-
为什么它被否决了?请解释一下
-
@VivekKumar 我认为这不是问题所在。如果是的话会引发错误
-
@rock321987 是的,它可能是。但是在我们收到MCVE 之前,我们将如何决定?
标签: python python-3.x scikit-learn countvectorizer