Challenge: TF-IDF
Compito
Swipe to start coding
You have a text corpus stored in corpus
variable. Your task is to display the vector for the 'medical' unigram in a TF-IDF model with unigrams, bigrams, and trigrams. To do this:
- Import the
TfidfVectorizer
class to create a TF-IDF model. - Instantiate the
TfidfVectorizer
class astfidf_vectorizer
and configure it to include unigrams, bigrams, and trigrams. - Use the appropriate method of
tfidf_vectorizer
to generate a TF-IDF matrix from the'Document'
column in thecorpus
and store the result intfidf_matrix
. - Convert
tfidf_matrix
to a dense array and create aDataFrame
from it, setting the unique features (terms) as its columns. Store the result in thetfidf_matrix_df
variable. - Display the vector for
'medical'
as an array.
Soluzione
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 8
single
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Suggested prompts:
Riassuma questo capitolo
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 3.45
Challenge: TF-IDF
Scorri per mostrare il menu
Compito
Swipe to start coding
You have a text corpus stored in corpus
variable. Your task is to display the vector for the 'medical' unigram in a TF-IDF model with unigrams, bigrams, and trigrams. To do this:
- Import the
TfidfVectorizer
class to create a TF-IDF model. - Instantiate the
TfidfVectorizer
class astfidf_vectorizer
and configure it to include unigrams, bigrams, and trigrams. - Use the appropriate method of
tfidf_vectorizer
to generate a TF-IDF matrix from the'Document'
column in thecorpus
and store the result intfidf_matrix
. - Convert
tfidf_matrix
to a dense array and create aDataFrame
from it, setting the unique features (terms) as its columns. Store the result in thetfidf_matrix_df
variable. - Display the vector for
'medical'
as an array.
Soluzione
Tutto è chiaro?
Grazie per i tuoi commenti!
Awesome!
Completion rate improved to 3.45Sezione 3. Capitolo 8
single