July 2018
Beginner to intermediate
146 pages
3h 39m
English
The next step is to create a DataFrame where each row represents the TF-IDF vector of the overview feature of the corresponding movie in our main DataFrame. To do this, we will use the scikit-learn library, which gives us access to a TfidfVectorizer object to perform this process effortlessly:
#Import TfIdfVectorizer from the scikit-learn libraryfrom sklearn.feature_extraction.text import TfidfVectorizer#Define a TF-IDF Vectorizer Object. Remove all english stopwordstfidf = TfidfVectorizer(stop_words='english')#Replace NaN with an empty stringdf['overview'] = df['overview'].fillna('')#Construct the required TF-IDF matrix by applying the fit_transform method on the overview featuretfidf_matrix = tfidf.fit_transform(df['overview']) ...Read now
Unlock full access