First, I downloaded the detailed voting results of the Grand Final of 2016 from the official Eurovision website. This is a neatly organized xls file. It lets you look at how many points were awarded from each jury member to each participating country. So far so good. Any project that doesn’t start with scraping the web is a great project.

The first question I wanted to ask was: which juries voted in the most similar way? First, here’s some background on how jury vote works. Each country has four jury members, who rank each Grand Final act on a scale from 1 to 25, where 1 is first place and 25 is the last place.

To answer my question, I compared how similar each pair of jury members voted within each country and then averaged the results. To get a correlation score for each pair of judges, I used Pearson correlation coefficient. Let’s say that we wanted to compute an average correlation score between jury member pairs for Poland. The formula to do so would look like this:

$$similarity(Poland) = \frac{1}{6}pearson(Poland_A, Poland_B) + pearson(Poland_A, Poland_C) + \\\\

pearson(Poland_A, Poland_D) + pearson(Poland_B, Poland_C) + pearson(Poland_B, Poland_D) + \\\\ pearson(Poland_C, Poland_D)$$

OK, let’s look into some results. As I mentioned before, I used Pearson’s correlation coefficient to compute the similarity between voting patterns for each judge pair. Pearson’s correlation coefficient can go from -1, when variables are reversely correlated to 1, when they are perfectly correlated.

Ukraine judges agreed on average the most, achieving the average correlation score of 0.81. Here is the top five of the most similar judging, together with their average Pearson’s correlation score.

$$

\begin{array}{c|c}

\text{Country} & \text{Average correlation score}\\

\hline

\text{Ukraine} & 0.81 \\

\text{Germany} & 0.75\\

\text{Armenia} & 0.72\\

\text{Malta} & 0.7\\

\text{Czech Republic} & 0.7

\end{array}

$$

Let’s look into the countries whose judges disagreed the most.

$$

\begin{array}{c|c}

\text{Country} & \text{Average correlation score}\\

\hline

\text{Denmark} & -0.08 \\

\text{San Marino} & 0.16\\

\text{Hungary} & 0.21\\

\text{Macedonia} & 0.3\\

\text{Ireland} & 0.31

\end{array}

$$

Denmark is on top of that list. It may be because one of the judges misunderstood the judging rules. As a result, she ranked her favorite act last, and her least favorite act first.

Here are the visualizations of the voting. Notice how Denmark’s colors seem to be distributed in a random way. Ukraine’s chart, however, contains vertical bars of similar color. These indicate that the judges awarded the same country a similar rank. It seems that judges agreed the most about the top and the bottom of their ranks — notice the bars for Belgium, Azerbaijan, Germany, Cyprus, Lithuania, and Russia.

]]>In [1]:

```
a = float('inf')
b = float('inf')
```

In [2]:

```
a / b
```

Out[2]:

In [3]:

```
a - b
```

Out[3]:

It’s very easy for NaN to enter your data:

In [4]:

```
from scipy.stats.stats import pearsonr
a = [0, 0, 0, 0, 0]
b = [0, 0, 0, 0, 0]
pearsonr(a, b)[0]
```

Out[4]:

It’s also very easy for NaN to quietly propagate:

In [5]:

```
c = float('nan')
c + 4022
```

Out[5]:

NaN silently breaks sorting

In [6]:

```
d = [4, float('nan'), 2, 1]
```

In [7]:

```
e = float('nan')
```

In [8]:

```
e < 15234
```

Out[8]:

In [9]:

```
e > 15234
```

Out[9]:

In [10]:

```
e == 15234
```

Out[10]:

In [11]:

```
e == e
```

Out[11]:

Ways to get around sorting with NaN values

In [12]:

```
import math
f = [4, float('nan'), 2, 1]
```

In [13]:

```
sorted([x for x in f if not math.isnan(x)])
```

Out[13]:

In [14]:

```
sorted([x for x in f if x == x])
```

Out[14]:

In [16]:

```
sorted(f, key=lambda x: x if not math.isnan(x) else 0, reverse=True)
```

Out[16]: