Practical Exercises
Exercise 1: Bag of Words
Task: Use the CountVectorizer from scikit-learn to transform the following text corpus into a Bag of Words representation:
"Text processing is important for NLP.",
"Bag of Words is a simple text representation method.",
"Feature engineering is essential in machine learning."
Solution:
from sklearn.feature_extraction.text import CountVectorizer
"Text processing is important for NLP.",
"Bag of Words is a simple text representation method.",
"Feature engineering is essential in machine learning."
# Initialize the CountVectorizer
vectorizer = CountVectorizer()
# Transform the text data
X = vectorizer.fit_transform(documents ...