Detecting Fake Hotel Reviews with Text Classification

Table of Contents

  1. Introduction and setup (this page)
  2. Loading and Exploring the Data
  3. Building Feature Vectors and Training the Model
  4. Testing Classifier Accuracy
  5. Building a Training Pipeline
  6. Tuning Hyperparameters using Grid Search
  7. Exercises

Introduction

The goal of this guide is to explore the main scikit-learn text processing tools on a single practical task: analyzing a collection of hotel reviews to detect whether each review is truthful (real) or deceptive (fake). Unlike topic classification—where specific subject nouns like "gpu" or "atheism" reveal the category—deception detection requires recognizing subtle stylistic patterns, pronoun usage, and hyperbolic phrasing.

In this section we will see how to:

Tutorial setup

To get started with this tutorial, create a virtual environment and install KaggleHub, NumPy, and scikit-learn. Run these commands from the tutorial folder:

uv venv --python 3.14
uv pip install kagglehub numpy scikit-learn
# Activate the venv using commands for your os and shell

In VS Code, select the .venv environment as the Python interpreter.

References

Acknowledgments


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.


  1. Data leakage is when information from the test data gets into the training process, for example by building the vocabulary or the IDF weights from all the reviews instead of only the training reviews. It makes a model look more accurate on the test set than it will be on new reviews. ↩