Bird
0
0

Given this Python snippet for domain-specific sentiment prediction:

medium📝 Predict Output Q13 of 15
NLP - Sentiment Analysis Advanced
Given this Python snippet for domain-specific sentiment prediction:
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression

texts = ['Great battery life', 'Poor screen quality', 'Excellent camera']
labels = [1, 0, 1]  # 1=positive, 0=negative

vectorizer = CountVectorizer()
X = vectorizer.fit_transform(texts)
model = LogisticRegression()
model.fit(X, labels)

new_text = ['Battery lasts long']
X_new = vectorizer.transform(new_text)
pred = model.predict(X_new)

What is the expected output of pred?
A[1]
B[0]
CError due to missing labels
D[1, 0]
Step-by-Step Solution
Solution:
  1. Step 1: Understand training data and labels

    The model is trained on positive and negative examples related to product features.
  2. Step 2: Predict sentiment for new text

    'Battery lasts long' is similar to 'Great battery life', which is labeled positive (1), so prediction should be positive.
  3. Final Answer:

    [1] -> Option A
  4. Quick Check:

    Similar positive text predicts 1 = A [OK]
Quick Trick: New text similar to positive training predicts positive [OK]
Common Mistakes:
MISTAKES
  • Expecting multiple predictions for single input
  • Confusing labels or expecting error
  • Ignoring vectorizer transform step

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More NLP Quizzes