Skip to content

Word Frequencies with TfidfVectorizer code #35

@imsanjoykb

Description

@imsanjoykb

from sklearn.feature_extraction.text import TfidfVectorizer

list of text documents

text = ["The quick brown fox jumped over the lazy dog.",
"The dog.",
"The fox"]

create the transform

vectorizer = TfidfVectorizer()

tokenize and build vocab

vectorizer.fit(text)

summarize

print(vectorizer.vocabulary_)
print(vectorizer.idf_)

encode document

vector = vectorizer.transform([text[0]])

summarize encoded vector

print(vector.shape)
print(vector.toarray())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions