BOW using product reviews
You practiced a BOW on a small dataset. Now you will apply it to a sample of Amazon product reviews. The data has been imported for you and is called reviews. It contains two columns. The first one is called score and it is 0 when the review is negative, and 1 when it is positive. The second column is called review and it contains the text of the review that a customer wrote. Feel free to explore the data in the IPython Shell.
Your task is to build a BOW vocabulary, using the review column.
Remember that we can call the .get_feature_names() method on the vectorizer to obtain a list of all the vocabulary elements.
Bài tập này là một phần của khóa học
Sentiment Analysis in Python
Hướng dẫn bài tập
- Create a CountVectorizer object, specifying the maximum number of features.
- Fit the vectorizer.
- Transform the fitted vectorizer.
- Create a DataFrame where you transform the sparse matrix to a dense array and make sure to correctly specify the names of columns.
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
from sklearn.feature_extraction.text import CountVectorizer
# Build the vectorizer, specify max features
vect = ____(____=100)
# Fit the vectorizer
vect.____(reviews.review)
# Transform the review column
X_review = vect.____(reviews.review)
# Create the bow representation
X_df=pd.DataFrame(X_review._____, columns=___.____)
print(X_df.head())