Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

EDA Demo: Wine Reviews

DS 2023 | Communicating with Data

Overview

Load the dataset, inspect its structure, and look at the first six rows.

Set up

<class 'pandas.DataFrame'>
RangeIndex: 129971 entries, 0 to 129970
Data columns (total 8 columns):
 #   Column    Non-Null Count   Dtype  
---  ------    --------------   -----  
 0   title     129971 non-null  str    
 1   country   129908 non-null  str    
 2   province  129908 non-null  str    
 3   variety   129970 non-null  str    
 4   taster    103727 non-null  str    
 5   price     120975 non-null  float64
 6   points    129971 non-null  int64  
 7   content   129971 non-null  str    
dtypes: float64(1), int64(1), str(6)
memory usage: 54.5 MB
Loading...

Review nulls

<Figure size 2500x1000 with 2 Axes>

What countries are most represented?

Find out which are the most represented countries in the dataset.

Also determine the distribution of country frequency.

Use the distribution stats to pick a subset of countries to work with.

country US 54504 France 22093 Italy 19540 Spain 6645 Portugal 5691 Name: count, dtype: int64

Figure 1

<Figure size 1200x600 with 2 Axes>
Figure 1: This histogram shows the log frequency of observations (reviews) by country. The distribtion of country counts follows a classic power law distribution, and so it helps to show the series in the linear space of a logarithm. The box plot on the right shows where the outliers are. In this case, the outliers are the rule, not the exceptions. They account for the vast majority of content in the dataset. We use this information to truncate our dataset to include only those reviews that belong to the top 7 countries: US, France, Italy, Spain, Portugal, Chile, and Argentina.
['US', 'France', 'Italy', 'Spain', 'Portugal', 'Chile', 'Argentina']
(116745, 8)

Which tasters review which countries?

Let’s use an alluvial to take a quick look.

Loading...

Note that we can’t assign a color to a variable since we haven’t defined any categorical types.

Note also that there is a big chunk of unnamed tasters -- these do not show up in value counts unless you tell it show them.

taster NaN 25720 Roger Voss 24359 Michael Schachner 14885 Kerin O’Keefe 10776 Virginie Boone 9537 Paul Gregutt 9345 Matt Kettmann 6332 Sean P. Sullivan 4934 Jim Gordon 4177 Anna Lee C. Iijima 2435 Joe Czerwinski 1413 Anne Krebiehl MW 1395 Lauren Buzzeo 619 Alexander Peartree 415 Susan Kostrzewa 232 Carrie Dykes 139 Fiona Adams 27 Christina Pickard 5 Name: count, dtype: int64

So, let’s convert these nulls into ‘Anonymous’ make the column categorical.

Loading...

We can also view this as a heatmap.

Loading...

Figure 2

<Figure size 640x480 with 1 Axes>
Figure 2: This heatmap shows the distribution of tasters and countries of reviewed wines. The darker squares show both prolific writing and heavy concentration in a particular area. Anonymous accounts for a large percentage of interviews and concentrate in the US and Italy. The most prolific taster is Roger Voss, who devotes most of his time to French and Portuguese wines.

Here look at summary statistics of countries and tasters.

<Figure size 1000x500 with 2 Axes>

Comparing Price and Points

Let’s compare price and points.

These two measures are related in that both assign value to the wine.

The first is assign by the market, the second by individual tasters.

It will be interesting to see how they are related.

First, let’s prepare a separate dataframe for the two variables.

Loading...

Even though both variables are numeric measurements, they also have a discrete quality that makes them suitable to be treated as categories.

It is often the case that numbers are used in this way, especially when they represent human assignments of value.

Given this, let’s start off with a heatmap of their value counts.

Loading...

Viewed in this way, an interesting pattern is emerges: prices cluster at 5 dollar intervals, forming bands in the heatmap.

In addition, each band has a central value.

Taking advantage of this observation, we can produce a reduced representation of the heatmap showing only prices at 5 dollar intervals.

The result is a clear visualization of where the most wines are in price/point space.

The most popular wine appears to be an 88 point wine for $20\$20.

Loading...

Here’s the same heatmap using Seaborn.

<Figure size 640x480 with 1 Axes>

Note that neither a histogram nor a density plot shows the pattern of five dollar clustering, at least not without doing a search across bin sizes.

In other words, if you rely solely on these plots for EDA, you might miss this important structural feature.

<Figure size 1000x400 with 2 Axes>

Figure 2a

Probably the best way to represent the clustering pattern in the prices is to use a bar chart.

<Figure size 1000x500 with 1 Axes>
Figure 2a: The bar chart above shows that wine prices cluster at five dollar intervals. This pattern represents a prefence among sellers of wine, which may in turn their perceptions of price points that will appeal most to buyers. The most frequent price is $20.

At $20, here are is the distribution of points.

<Figure size 640x480 with 1 Axes>
<Figure size 640x480 with 1 Axes>

Does price predict points?

Now let’s explore the functional relationship between the two variables.

In particular, can we use price to predict points?

Or does the market not always get it right?

Let’s look at the relationship between price and points first.

Here, we use a scatterplot, treating the two series of integers as floats.

<Figure size 640x480 with 1 Axes>

Here we see a classic tornado pattern.

This implies that a lot of data is concentrated at one end of the x axis.

We can spread the crowded data points out by showing the x axis on a log scale.

<Figure size 640x480 with 1 Axes>

Here we see that the there is a linear relationship between the two variables with a great deal of variance.

This variance is probably due to the market, the constant game of cat and mouse between seller and buyer, producer and consumer.

Let’s model this relationship and then use it as a tool later.

Loading...

Figure 3

<Figure size 640x480 with 1 Axes>
Figure 3: This scatterplot of the log of the price versus taster points shows an upward bias. The line is a crude linear model of the rate by which points increase with price. According to the model, for evey unit increase in the log of price, the points go up by 6.65. The plot shows that there are many overpriced and underpriced wines — i.e. wines to avoid and wines to buy.

Where are the bargain wines?

Let’s say that a bargain wine is one that meets the following criteria:

  • Punches above its weight class, i.e. points above the model line.

  • Is affordable, i.e. is at or below the median price.

  • Is good, i.e. at or above the median points.

Median price:	26
Median pionts:	88

Note these value correspond closely to the most popular combo of price and points we discovered in the heatmap above.

Figure 4

<Figure size 600x600 with 3 Axes>
Figure 4: This scatterplot shows the relationship between log price, points, and a regression model. The reduced opactity of the points, along with the box plots for each axis show a different concentraton of data. At the lower end of price, wines tend to be below the model (i.e. bad buys) whereas at the upper end of price they tend to be above the model (i.e. good buys). By overlaying the median values of points and log price we can define a region where the bargain wines live. As it turns out, we don't need the model to define this region: the medians will do.

Let’s just buy wine that is above the median in points and below the median in price.

N = 49,654
Loading...

Best bang for you buck?

What about wines that are not necessarily above the model line, but which have a high ratio of points to price?

This would be decent wines at a very low price.

Let’s call this the “bang for you buck index”, or BBIBBI.

BBI=pointspriceBBI = \dfrac{\text{points}}{\text{price}}

Look at the distribution of BBI.

<Figure size 1000x200 with 1 Axes>
N = 10
Loading...
N = 40
Loading...
N = 281
Loading...

Yet another method: Cheapest in class

The best wines for $100 or less.

N = 37,211
Loading...

Which countries have the best buys?

<Figure size 1000x1000 with 5 Axes>

We create a function to pop out wedges from the pie.

<Figure size 1000x1000 with 5 Axes>
Figure: The pie charts above show which countries tend to produce the best buys. Although not the most frequent wine in the best buy categories, Portugal emerges as a country from which a relatively high percentage of wines are a good buy. In the Bang-for-Buck Group 1, Spain is the king.

Actually, the figure above is an example of an inapprpriate use of the pie chart.

The reason is that the values, as relative frequencies, do not sum up to anything meaningful.

Since we want to compare magnites, not inspect composition, a better tool here is the bar chart.

Figure 5

<Figure size 1000x800 with 5 Axes>
Figure 5: The bar charts above show which countries tend to produce the best buys. The bars show relative frequencies, computed by dividing the number of wines from a country for a best buy category by the total number of wines for the country. The resulting numbers are very small and so are not listed; what matters are the relative proportions. Although not the most frequent wine in the best buy categories, Portugal emerges as a country from which a relatively high percentage of wines are a good buy. In the Bang-for-Buck Group 1, Spain is the king.

Looking at all of it

Loading...

This interactive plot shows all the things we looked at above.

One interesting thing that falls out is that the blue diamonds, i.e. wines that are bargains and yet not best in class, constitute only one one line of data — at 89 points.

The reason they are not cheapest in class is because we arbitrarily drew the line at 90 for that metric.

What this shows is that there are no bargain wines below 89.

This causes us to realize that it might be a good idea to visualize the distribution of price and points for each of our metrics.