Learn Python

Introduction to Network Analysis with Python

Today we are going to show what the Networks analytics is and how to do it, let me first give you a question what are some examples of networks, well one example maybe is social network. In a social network we’re modeling the relationships between people, here’s another one transportation networks, in this one we’re modeling the connectivity between locations as determined by roads or fight/flight paths connecting them at its. Networks are a useful tool for modeling relationships between entities.

By modeling your data as network, you can end up gaining insight into what entities or nodes are important, such as broadcasters or influencers in a social network, additionally you can start to think about optimizing transportation between cities, finally you can leverage the network structure to find communities in the network.

Let’s go a bit more technical networks are described by two sets of items : nodes and edge together these from a network otherwise know in mathematical terms as a graph, nodes and edges can have metadata associated for then, for example let’s say there are two friends Hugo and myself who met on the 21st of May 2016, in this case the nodes may be Hugo and myself with metada stored in a key value pair as ID and Age, the friendship is represented as a line between the two nodes and may have a meta da such as date which represents the date on which we first met.

In the python world there’s a libraries called Network X that allows us to manipulate, analyze and model graph data, let’s see how we can use the Network X API to analyze graph datamemory.

Network X is typically imported as NX using using NX.graph, we can initialize an empty graph to which we can add nodes and edeges, I can for example the integers 1, 2, 3 as nodes using the add nodes from methods passing in the list 1, 2, 3 as an argument. The graph object G has dot nodes methods that allow us to see what nodes are present in a graph and return a list of nodes.

If we add an edege between the nodes 1 and 2 we can then use the G edge method to return a list of tuples which represent the edge in which each tuple shows the nodes that are present on that edge.

Next time we’re going to show how to add metadata to your network and manipulate it.

If you like this article, follow us in our facebook page : the over day and let’s your friends know by sharing it on social media.