Observe The Friend Paradox in Facebook Data Using Python
By: Khuyen Tran
Tags: Data Analysis, Graph, Data Visualization, Data Science, Python

Observe The Friend Paradox in Facebook Data Using Python

Motivation

On average do your friends have more friends than you? If you are an average person, there is a high chance that you have fewer friends than your friends.

This is called the friendship paradox. This phenomenon states that most people have fewer friends than their friends have, on average.

In this article, I will demonstrate why such a paradox exists, and whether we can find the paradox in Facebook data.

GIF by Author — Interact with the graph here.

Minimal Example

To understand why the friend paradox exists, let’s start with a minimal example. We will create a network of people. Two people are friends if they are listed in the same Python tuple.

Now we will use Pyvis to visualize the network.

pip install pyvis

If you move the nodes around, you can see that Ben is the center of the circle of friends.

We are interested in finding what percentage of people in this network have fewer friends than their friends do on average. We will create multiple functions that help us answer this question. The functions are:

Get friends of a specific person:

For example, Lauren’s friends are:

>>> get_friends(friends, "Lauren")

['Khuyen', 'Ben']

Get the number of friends a specific person has:

>>> get_friends(friends, "Lauren")

2

Get the numbers of friends a person’s friends have:

>>> num_friends_map = get_num_friends_map(friends)

>>> get_num_friends_of_a_person_friends(friends, "Lauren",

... num_friends_map) [3, 5]

The result shows that Khuyen has 3 friends and Ben has 5 friends.

Get the number of friends a person’s friends have on average:

>>> get_average_friends_of_a_person_friends(friends, "Lauren")

4.0

The output shows that the number of friends Lauren’s friends have on average is 4, which is higher than the number of friends she has.

Image by Author

If we observe the picture above carefully, we can see that Ben’s number of friends gives a boost to the number of friends Lauren’s friends have on average.

Since Ben has many friends, many of his friends will be in a similar situation as Lauren. In other words, the number of friends their friends have on average is higher than their number of friends because one or two of their friends are the influencers.

Get the number of friends for all people in the network

In the table above,

The column num_friends shows the number of friends a person has.

shows the number of friends a person has. The column avg_friends_of_friends shows the number of friends a person’s friends have on average.

shows the number of friends a person’s friends have on average. The column friends_have_more_friends indicates whether a person’s friends have more friends than himself/herself on average.

Let’s find out what percentage of people in the network have fewer friends than their friends have on average.

0.8333333333333334

As we can see from the table above, only Ben has more friends has his friends have on average. It is because he is the influencer in the group.

Analyze Facebook Network

The Facebook data consists of friend lists from Facebook. Facebook data was collected from survey participants, and the users in this data have been anonymized.

You can download the data from here. After downloading the data, unzip and save it as facebook_combined.txt .

We will use the previous functions to get the number of friends people in the network have.