Session Ready
Exercise

Tf-idf

While counts of occurrences of words can be useful to build models, words that occur many times may skew the results undesirably. To limit these common words from overpowering your model a form of normalization can be used. In this lesson you will be using Term frequency-inverse document frequency (Tf-idf) as was discussed in the video. Tf-idf has the effect of reducing the value of common words, while increasing the weight of words that do not occur in many documents.

Instructions
100 XP
  • Import TfidfVectorizer from sklearn.feature_extraction.text.
  • Instantiate TfidfVectorizer while limiting the number of features to 100 and removing English stop words.
  • Fit and apply the vectorizer on text_clean column in one step.
  • Create a DataFrame tv_df containing the weights of the words and the feature names as the column names.