Khang Thai
  • About
  • Experience
  • Projects
  • Contact
  • Resume

Amazon Purchase Predictor

A five-model bake-off on customer spending, won by a random forest at RMSE 0.113.
Author

Khang Thai

Published

July 28, 2024

R Random Forest Ridge & Lasso KNN Regression Caret Tidyverse

A Kaggle-style regression problem: predict log_total — total customer spend on a log scale — from demographic and transaction features. The interesting part was not the winning model but how narrow the gap between models turned out to be, and how much of the improvement came from feature work instead.

0.113RMSE (random forest)
0.003Standard error
>0.95R² on held-out data
5Model families compared

Preprocessing

  • Handled missing values, then normalized and transformed the skewed spending variables — the log transform on the response is what makes the residuals behave.
  • Screened features on correlation and importance before modeling rather than throwing everything at the wall.

Model selection

  • Compared linear regression, ridge, lasso, random forest and KNN regression under the same cross-validated protocol.
  • Tuned hyperparameters with cross-validation in caret, so the comparison was between tuned models rather than default settings.
  • KNN underperformed the tree-based models — unsurprising given the mix of categorical and count features, where distance metrics get awkward.

Feature engineering

  • Found count_hh4 and count_G — household size and order-count features — to be the strongest correlates of log_total.
  • Tested interactions between income level and purchase frequency, which sharpened the fit for high-frequency households.

Result

  • The final random forest reached RMSE 0.1129 (SE 0.0030) with R² above 0.9587.
  • Household size, order count, and income level were the significant predictors of Amazon spend — the model is essentially learning that more people in a household with more orders spend more, and quantifying by how much.
  • Worth naming the limitation: the strong R² partly reflects predictors that are close relatives of the response. It's a good predictive model and a weak causal one.
Project repository Full report (PDF)
Task Manager LA Airbnb Analysis

© 2026 Khang Thai · Built with Quarto