Your first TfIdf
In this exercise, you will apply the TfIdf method to the small annak
dataset, containing the first sentence of Anna Karenina by Leo Tolstoy.
Your task will be to work with this dataset and apply the TfidfVectorizer()
function. Recall that performing a numeric transformation of text is your first step in being able to understand the sentiment of the text. The Tfidf vectorizer is another way to construct a vocabulary from our sentiment column.
Este ejercicio forma parte del curso
Sentiment Analysis in Python
Instrucciones del ejercicio
- Import the function for building a TfIdf vectorizer from
sklearn.feature_extraction.text
. - Call the
TfidfVectorizer()
function and fit it on theannak
dataset . - Transform the vectorizer.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
# Import the required function
____
annak = ['Happy families are all alike;', 'every unhappy family is unhappy in its own way']
# Call the vectorizer and fit it
anna_vect = ____.___(annak)
# Create the tfidf representation
anna_tfidf = anna_vect.____(annak)
# Print the result
print(anna_tfidf.toarray())