Challenge: TF-IDF
Task
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
TfidfVectorizerclass to create a TF-IDF model. - Instantiate the
TfidfVectorizerclass astfidf_vectorizerand configure it to include unigrams, bigrams, and trigrams. - Use the appropriate method of
tfidf_vectorizerto generate a TF-IDF matrix from the'Document'column in thecorpusand store the result intfidf_matrix. - Convert
tfidf_matrixto a dense array and create aDataFramefrom it, setting the unique features (terms) as its columns. Store the result in thetfidf_matrix_dfvariable. - Display the vector for
'medical'as an array.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 8
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.45
Challenge: TF-IDF
Swipe to show menu
Task
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
TfidfVectorizerclass to create a TF-IDF model. - Instantiate the
TfidfVectorizerclass astfidf_vectorizerand configure it to include unigrams, bigrams, and trigrams. - Use the appropriate method of
tfidf_vectorizerto generate a TF-IDF matrix from the'Document'column in thecorpusand store the result intfidf_matrix. - Convert
tfidf_matrixto a dense array and create aDataFramefrom it, setting the unique features (terms) as its columns. Store the result in thetfidf_matrix_dfvariable. - Display the vector for
'medical'as an array.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 8
single