Skip to main content

Coffee Rating Prediction

·664 words·4 mins
Alex Haslam
Author
Alex Haslam
I’m an engineer based in London, with expertise in optimisation, machine learning and simulation.
Table of Contents

I enjoy drinking good coffee, but buying specialty coffee is pretty risky. A bag of coffee can easily cost £10–15 and it’s hard to know whether you will like it based on just the country of origin or highly subjective tasting notes. I wondered if I could use a data-driven approach to help me work out if a coffee is likely to be good or not.

To test this out, I built an end-to-end regression model using XGBoost and then deployed it on AWS Lambda. To make it easy to interact with, I wired it up to an interactive Streamlit dashboard. The source code is available on GitHub.

Objective & Dataset
#

The objective of this project is to be able to predict how highly rated a coffee would be on CoffeeReview.com based purely on information about the coffee such as:

  • Origin
  • Roaster and roasting style
  • Price
  • Flavour profile

I used a dataset from Kaggle containing ratings for ~1,900 coffees.

Feature Selection & Exploratory Analysis
#

We have quite a few features available, but not all lead to a significant improvement in the accuracy of the model. I began by assessing the importance of the different features quantitatively using correlation and mutual information:

FeatureMetricScoreInsight
roasterMutual information0.670Largest overall influence on rating
country_of_originMutual information0.159Origin country strongly impacts cup quality
price_per_100gCorrelation coefficient0.242Moderately positive correlation with rating
roaster_countryMutual information0.068Roaster location contributes slight signal
roastMutual information0.046Lighter and medium roasts score higher than dark roasts

Price vs Rating
#

To visualise the influence of price on the rating, we can look at the relationship between price_per_100g and rating:

There is positive correlation between the two variables, though with noticeable scatter. There is also evidence of diminishing returns as price increases, with the curve flattening off at higher prices.

Influence of Origin
#

Looking at average ratings by global growing region:

East African coffees (e.g. Ethiopia, Kenya) achieve the highest average ratings, whereas Central American lots show slightly lower averages on CoffeeReview.

Flavour Profile Impact
#

By parsing tasting notes from review text into categorical indicators, we can compute the difference in mean rating for coffees with versus without each flavour note:

Fruit and floral notes show the largest positive delta on review score, while resinous notes correspond with lower ratings.

Predictive Modelling
#

I trained and evaluated regularised linear regression and gradient-boosted decision trees (XGBoost) using 5-fold cross-validation.

Hyperparameter Tuning on XGBoost
#

Evaluating root-mean-square error (RMSE) on training and validation folds across increasing maximum tree depth:

As max_depth increases beyond 2, the training loss decreases without a corresponding decrease in validation loss, indicating overfitting. A shallower tree with max_depth = 2 and a learning rate of eta = 0.3 provided the best validation performance.

Model Comparison
#

Comparing training and test losses across models:

Both the regularised linear model and tuned XGBoost model achieve comparable test performance. Linear regression provides strong interpretability, while boosted trees capture non-linear interactions between roaster reputation and specific origins.

Serverless Deployment
#

To make the model interactively accessible away from my computer, I deployed the inference pipeline using a containerised serverless architecture:

graph TD
E[User Browser]-.->A[Streamlit Web App]
A--HTTP Request (JSON Features)-->B[AWS Lambda]
B--Rating Prediction-->A
subgraph Docker container on AWS Lambda
D[Model Runtime / Scikit-Learn + XGBoost]
end
B---D
  • Docker Container: Packaged the Python runtime and dependencies using poetry and published the container image to Amazon ECR.
  • AWS Lambda Function URL: Served via a serverless Lambda Function URL authenticated via IAM, so there are no idle costs or servers to maintain.
  • Streamlit Web Dashboard: Built an interactive UI where users can adjust roast, origin, price and flavour notes to receive real-time score predictions.

Streamlit app

Try It Out
#

You can try out the deployed dashboard here next time you’re buying coffee to see how different origins, roasts and flavour notes score!