Lab 05: Wine

For Lab 05, you will use wine data to develop a model that will predict a wine’s quality given it’s characteristics.

Background

Wine is a popular alcoholic beverage made from fermented fruit. A Sommelier is a professional that specializes in wine services, especially wine-food pairings. Sommeliers receive extensive training.

Scenario and Goal

Who are you?

  • You work for a startup that wants to create an AI Sommelier.

What is your task?

  • Rather than using a highly trained human, you will purchase chemistry equipment to generate physicochemical data for wines, and train models based on previous wine quality reviews by human sommeliers. Your goal is to create a model that predicts a wine’s quality given its physicochemical characteristics.

Who are you writing for?

  • To summarize your work, you will write a report for the startup’s founders. They are experts in the wine industry, but not necessarily in data science.

Data

To achieve the goal of this lab, we will need wine quality data. The necessary data is provided in the following files:

Source

The original source of the data is the following paper:

  • Cortez, P., Cerdeira, A., Almeida, F., Matos, T., & Reis, J. (2009). Modeling wine preferences by data mining from physicochemical properties. Decision support systems, 47(4), 547-553. https://doi.org/10.1016/j.dss.2009.05.016

However, the data from this paper has become a standard dataset in the machine learning community, and thus is made available via the UC Irvine Machine Learning Repository.

The original data contains two separate datasets, one for red wine and one for white wine. Here, we have combined the data and added a column for the color of the wine. We have made additional modifications to the original data.

Data Dictionary

Each observation in the train, test, and (hidden) production data contains information about a particular Portuguese “Vinho Verde” wine.

Vinho verde is a unique product from the Minho (northwest) region of Portugal. Medium in alcohol, is it particularly appreciated due to its freshness (specially in the summer).

Original and complete documentation for this data can be found in the original paper. Additionally, minimal documentation is provided by the UCI MLR.

Response

quality

  • [int64] the quality of the wine based on evaluation by a minimum of three sensory assessors (using blind tastes), which graded the wine in a scale that ranges from 0 (very bad) to 10 (excellent)

Features

color

  • [object] the (human perceivable) color of the wine, red or white

fixed acidity

  • [float64] grams of tartaric acid per cubic decimeter

volatile acidity

  • [float64] grams of acetic acid per cubic decimeter

citric acid

  • [float64] grams of citric acid per cubic decimeter

residual sugar

  • [float64] grams of residual sugar per cubic decimeter

chlorides

  • [float64] grams of sodium chloride cubic decimeter

free sulfur dioxide

  • [float64] milligrams of free sulfur dioxide per cubic decimeter

total sulfur dioxide

  • [float64] milligrams of total sulfur dioxide per cubic decimeter

density

  • [float64] the total density of the wine in grams per cubic centimeter

pH

  • [float64] the acidity of the wine measured using pH

sulphates

  • [float64] grams of potassium sulphate cubic decimeter

alcohol

Data in Python

To load the data in Python, use:

import pandas as pd
wine_train = pd.read_parquet(
    "https://cs307.org/lab/data/wine-train.parquet",
)
wine_test = pd.read_parquet(
    "https://cs307.org/lab/data/wine-test.parquet",
)

Prepare Data for Machine Learning

Create the X and y variants of the data for use with sklearn:

# create X and y for train
X_train = wine_train.drop("quality", axis=1)
y_train = wine_train["quality"]

# create X and y for test
X_test = wine_test.drop("quality", axis=1)
y_test = wine_test["quality"]

You can assume that within the autograder, similar processing is performed on the production data.

Sample Statistics

Before modeling, be sure to look at the data. Calculate the summary statistics requested on PrairieLearn.

Models

For this lab you will select one model to submit to the autograder. You may use any modeling techniques you’d like, so long as it meets these requirements:

  • Your model must start from the given training data, unmodified.
    • Importantly, the types and shapes of X_train and y_train should not be changed.
    • In the autograder, we will call mod.predict(X_test) on your model, where your model is loaded as mod and X_test has a compatible shape with and the same variable names and types as X_train.
    • In the autograder, we will call mod.predict(X_prod) on your model, where your model is loaded as mod and X_prod has a compatible shape with and the same variable names and types as X_train.
    • We assume that you will use a Pipeline and GridSearchCV from sklearn as you will need to deal with heterogeneous data, and you should be using cross-validation to tune your model.
      • More specifically, you should create a Pipeline that is fit with GridSearchCV. Done correctly, this will store a tuned model that you can submit to the autograder.
  • Your model must have a fit method.
  • Your model must have a predict method.
  • Your model should be created with scikit-learn version 1.6.1 or newer.
  • Your model should be serialized with joblib version 1.4.2 or newer.
  • Your serialized model must be less than 5MB.

While you can use any modeling technique, each lab is designed such that a model using only techniques seen so far in the course can pass the checks in the autograder.

To obtain the maximum points via the autograder, your model must outperform the following metrics:

Test MAE: 0.5
Production MAE: 0.5

Submission

Before submission, especially of your report, you should be sure to review the Lab Policy document.

On Canvas, be sure to submit both your source .ipynb file and a rendered .html version of the report.