如何为计数器向量化器分配最大特征?

How can I allocate max features for counter vectorizer?

我用 sklearn 创建了 countvectorizer,但在“max_features”处出现语法错误。 “max_features”在我创建 TfidfVectorizer 时有效。如何在计数器向量化器上设置最大特征?

vectorizer = CountVectorizer(analyzer='word',
                         lowercase=False,
                         tokenizer=None,
                         preprocessor=None,
                         min_df=2,
                         ngram_range=(1,1)
                         max_features=1000
                         )

我想你在 ngram_range (1, 1) 之后错过了 ,

试试这个:

vectorizer = CountVectorizer(analyzer='word',
                     lowercase=False,
                     tokenizer=None,
                     preprocessor=None,
                     min_df=2,
                     ngram_range=(1,1),
                     max_features=1000
                     )