Exercises

Setup for All the Exercises

For each exercise, start with the KaggleHub download, CSV-loading, and train/test-splitting code from this tutorial. Use the same reviews_train, labels_train, reviews_test, and labels_test lists so you can compare your models on the same held-out test data.

Exercise 1: Stylometry and Stopwords

In topic classification, removing English stopwords (stop_words='english') often reduces noise. In this exercise, you will test whether removing stopwords helps or hurts when detecting deceptive hotel reviews.

Hints

Exercise 2: Incorporating Character and Word N-grams

In this exercise, you will explore whether character N-grams or multi-word phrases (bigrams and trigrams) better capture the formulaic writing style of fake reviewers.

Exercise 3: CLI fake review detector utility

Using the results of the previous exercises and the pickle module of the standard library, write a command line utility that reads a hotel review provided on stdin and predicts whether the review is 'truthful' or 'deceptive'.

Bonus point if the utility is able to give a confidence level for its predictions (hint: use loss='log_loss' in SGDClassifier or use MultinomialNB to enable .predict_proba()).


Creative Commons License AI Programming 1 Course Materials by Brian Bird, written in are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.