vectorizationtf-idfcountvectorizer

How can I allocate max features for counter vectorizer?


I created counter vectorizer with skitlearn, but got syntax error at "max_features". "max_features" worked when I created TfidfVectorizer. How can I set max features on counter vectorizer?

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

Solution

  • I think you missed , after ngram_range (1, 1).

    Try this :

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