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

52. Text Cleaning and TF-IDF in Python

Data Science

52.5 Practice, Tip and Close

Why. Close when TF-IDF + train-only fit is a habit, then classify sentiment.

How.

Chapter practice

  1. Build six fictional reviews; split; fit TfidfVectorizer on train only.
  2. Print shapes and ten feature names.
  3. Write why fitting the vectoriser on all data (including test) leaks information.

Thodkyaat sangaycha tar (quick recap)

  • TF-IDF weights distinctive words higher
  • fit on train, transform on test
  • ngrams help phrases like "not good"
  • Hinglish needs humble expectations + light normalisation

Samajla ka? Next: Chapter 53 — Sentiment Analysis Project in Python.

Ravindra Bagale's Tip

Fit the vectoriser on the train set only, and then transform the test set. If you fit it on all of the reviews, including the test set, test information leaks into the features.