Skip to content

how to select top most frequent features from a dfm #1253

Description

@Monduiz

I am looking through the documentation trying to do the same as max_features from tfidfvectorizer in scikit.

max_features is very clearly defined in tfidfvectorizer:

If not None, build a vocabulary that only consider the top max_features ordered by term frequency across the corpus.

Like say I I use tokens(x, what = "character") and I would like to adjust with
dfm(x, max_features =50000) .

It seems logical to me that this would be a dfm operation. I am missing what the operation is and when it appears in the workflow if its already there. Basically, the goal is to reduce the dfm matrix to the 50000 first term by frequency. max_count in dfm_trim would not accomplish that.

What is not clear to me in the documentation:

If dfm(x[1:50000]; does this selects the first 50000 by top word frequency?
If dfm(x, max_docfreq = 50000; does this selects the first 50000 by top word frequency?

Do I have to add another step with %>% dfm_sort(margin = "features") but then not sure how to select by features and frequency.

Thanks for the guidance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions