Complete the code to create a simple bag-of-words representation of text.
from sklearn.feature_extraction.text import CountVectorizer texts = ['I love AI', 'AI loves me'] vectorizer = CountVectorizer() X = vectorizer.[1](texts)
The fit_transform method learns the vocabulary and transforms the texts into vectors in one step.
Complete the code to remove stop words from the text using CountVectorizer.
vectorizer = CountVectorizer(stop_words=[1])
X = vectorizer.fit_transform(texts)Setting stop_words='english' removes common English stop words automatically.
Fix the error in the code that tries to vectorize text but uses an incorrect method.
vectorizer = CountVectorizer() X = vectorizer.[1](['sample text'])
The CountVectorizer does not have a predict or fit_predict method. Use fit_transform to learn and transform the text.
Fill both blanks to create a dictionary comprehension that filters words longer than 3 characters.
filtered_words = {word: len(word) for word in words if len(word) [1] 3 and word [2] 'the'}The code keeps words longer than 3 characters and excludes the word 'the'.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths, excluding short words.
result = [1]: [2] for w in words if len(w) [3] 4
The comprehension maps uppercase words to their lengths, only for words longer than 4 characters.