Complete the code to import the class used to convert text data into numbers.
from sklearn.feature_extraction.text import [1]
The CountVectorizer class converts text into a matrix of token counts, which is essential for text-based machine learning tasks like sentiment analysis.
Complete the code to create a logistic regression model for sentiment classification.
from sklearn.linear_model import [1]
LogisticRegression is commonly used for binary classification tasks like sentiment analysis.
Fix the error in the code to fit the vectorizer on the training text data.
vectorizer = CountVectorizer()
vectorizer.[1](train_texts)transform before fitting causes errors.predict on the vectorizer which is not a model.The fit method learns the vocabulary from the training texts. Using fit_transform would both fit and transform, but here only fitting is needed before separate transformation.
Fill both blanks to transform training texts and train the logistic regression model.
X_train = vectorizer.[1](train_texts) model.[2](X_train, train_labels)
transform without fitting vectorizer first.predict before training the model.First, fit_transform converts texts to numbers and learns vocabulary. Then, fit trains the model on these features and labels.
Fill all three blanks to predict sentiment on test data and calculate accuracy.
X_test = vectorizer.[1](test_texts) predictions = model.[2](X_test) accuracy = accuracy_score(test_labels, [3])
fit on test data which leaks training info.We transform test texts with transform, predict labels with predict, and then compare predictions to true labels to get accuracy.