Last active
December 3, 2020 13:32
-
-
Save vporiz/16aa44f322b733cb1659148f78c87bac to your computer and use it in GitHub Desktop.
TF-IDF computation in Sklearn
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.feature_extraction.text import TfidfVectorizer | |
corpus = [ | |
'This is the first document.', | |
'This document is the second document.', | |
'And this is the third one.', | |
'Is this the first document?', | |
] | |
vectorizer = TfidfVectorizer() | |
X = vectorizer.fit_transform(corpus) | |
print(vectorizer.get_feature_names()) | |
# returns ['and', 'document', 'first', 'is', 'one', 'second', 'the', 'third', 'this'] | |
print(X.shape) | |
# returns (4, 9) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment