Ravindra BagaleCourses & study guides मराठी Track your progress

53. Sentiment Analysis Project in Python

53.4 Traps and Guardrails

Why. Real mistakes: fitting TF-IDF on all text, skipping stratify, celebrating 90% accuracy on 10 rows, or shipping Hinglish noise without a baseline check.

What. Guardrails from earlier chapters still apply: split first, metrics beyond accuracy when classes skew, and honest demo size.

How.

Avoid these traps

  1. Never fit the vectoriser on train+test together.
  2. Keep random_state for reproducible demos.
  3. On tiny sets, treat metrics as smoke tests.
  4. Add more labelled lines before business decisions.
# BAD: leaks test vocabulary into the vectoriser
# vec.fit_transform(docs) # then split — do not do this

# GOOD: split first, then fit on X_train only (see 53.2)
print("Remember: split → fit vectoriser on train → transform test")