Challenge: Bag of Words
Task
Swipe to start coding
You have a text corpus stored in corpus variable. Your task is to display the vector for the 'graphic design' bigram in a BoW model. To do this:
- Import the
CountVectorizerclass to create a BoW model. - Instantiate the
CountVectorizerclass ascount_vectorizer, configuring it for a frequency-based model that includes both unigrams and bigrams. - Use the appropriate method of
count_vectorizerto generate a BoW matrix from the'Document'column in thecorpusand store the result inbow_matrix. - Convert
bow_matrixto a dense array and create aDataFramefrom it, setting the unique features (unigrams and bigrams) as its columns. Store the result in thebow_dfvariable. - Display the vector for
'graphic design'bigram as an array.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 5
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: Bag of Words
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 'graphic design' bigram in a BoW model. To do this:
- Import the
CountVectorizerclass to create a BoW model. - Instantiate the
CountVectorizerclass ascount_vectorizer, configuring it for a frequency-based model that includes both unigrams and bigrams. - Use the appropriate method of
count_vectorizerto generate a BoW matrix from the'Document'column in thecorpusand store the result inbow_matrix. - Convert
bow_matrixto a dense array and create aDataFramefrom it, setting the unique features (unigrams and bigrams) as its columns. Store the result in thebow_dfvariable. - Display the vector for
'graphic design'bigram as an array.
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 5
single