# How Python can help you understand the 'friend paradoxes'

Do your friends have more friends than you do? If you are an average person, chances are you have **less** friends than your friends.

These are called relationship paradoxes. This irony states that most people have fewer friends than their average friends.

In this article, I will show why such paradoxes exist, and whether we can find the paradoxes in Facebook data.

*Index*

## Minimum example

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

Now we will use Pyvis to see the network.

pip install pyvis

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

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

- Get friends from a special person:

For example, Lauren's friends:

>>> get_friends(friends, "Lauren") ['Khuyen', 'Ben']

- Find the numbers of friends of a particular person:

>>> 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.

- Find the average number of friends of one's friends:

>>> get_average_friends_of_a_person_friends(friends, "Lauren") 4.0

The result shows that Lauren's friends have 4 friends, which is higher than the number of friends she has.

If we look at the picture above carefully, we can see that Ben's friends' average number of friends boosts Lauren's friends on average.

Since Ben has many friends, many of his friends will be in a similar situation to Lauren. In other words, the number of friends their friends have is higher than the number of their friends due **one or two of their friends are influential.**

- Get the number of friends for everyone in the network

In the table above,

- The column
**num_friends**shows the number of friends a person has. - The column
**avg_friends_of_friends**shows the average number of friends a person has. - The column
**friends_have_more_friends**indicates whether a person's friends have more friends than he / she on average.

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

0.8333333333333334

## Check the Facebook network

The Facebook data includes lists of friends from Facebook. Facebook data was collected from the survey participants, and the users in this data are anonymous.

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

We will use the previous actions to find the number of friends people in the network have.

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

0.874721465709334

87% of people in the network have fewer friends than their average friends!

**Draw a picture of the winners**

What nodes affect the network? We see them using Pyvis.

Start by adding nodes to the network.

We will define influencers as those who have more friends than their average friends. We mark the nodes defined as influencers in red.

Add margins and show the network graph:

As we can see, the red nodes (people who have more friends than their average friends) tend to be in the middle of the graph. If we move a red node, a lot of blue nodes move with it. This indicates that these red nodes affect one or two subgroups in the network.

## Conclusion

Congratulations! You've just figured out what friend paradoxes are, and how to view these paradoxes in Facebook data using Python. I hope this article inspires you to see other paradoxes around you using visualization and data science techniques.

Feel free to fork and play with the code for this article in this repo.

*This article was originally published on Towards Data Science, you can find it here. Khuyen writes about basic data science concepts and enjoys playing with various algorithms and data science tools. You can connect with them on LinkedIn and Twitter.*

*
*Deja una respuesta

Related Posts