Book Image

Network Science with Python

By : David Knickerbocker
Book Image

Network Science with Python

By: David Knickerbocker

Overview of this book

Network analysis is often taught with tiny or toy data sets, leaving you with a limited scope of learning and practical usage. Network Science with Python helps you extract relevant data, draw conclusions and build networks using industry-standard – practical data sets. You’ll begin by learning the basics of natural language processing, network science, and social network analysis, then move on to programmatically building and analyzing networks. You’ll get a hands-on understanding of the data source, data extraction, interaction with it, and drawing insights from it. This is a hands-on book with theory grounding, specific technical, and mathematical details for future reference. As you progress, you’ll learn to construct and clean networks, conduct network analysis, egocentric network analysis, community detection, and use network data with machine learning. You’ll also explore network analysis concepts, from basics to an advanced level. By the end of the book, you’ll be able to identify network data and use it to extract unconventional insights to comprehend the complex world around you.
Table of Contents (17 chapters)
1
Part 1: Getting Started with Natural Language Processing and Networks
5
Part 2: Graph Construction and Cleanup
9
Part 3: Network Science and Social Network Analysis

Getting started with community detection

Before we can start, we need a network to use. Let’s use NetworkX’s Les Miserables graph that we used in the previous chapter since it held several separate communities:

  1. Loading the network is simple:
    import networkx as nx
    import pandas as pd
    G = nx.les_miserables_graph()

That’s all it takes to load the graph.

  1. There is a weight attribute that I do not want to include in the network because we don’t need edge weights for this simple demonstration. So, I’m going to drop it and rebuild the graph:
    df = nx.to_pandas_edgelist(G)[['source', 'target']]
    # dropping 'weight'
    G = nx.from_pandas_edgelist(df)

In those two steps, we converted the Les Miserables graph into a pandas edge list, and we kept only the source and target fields, effectively dropping the weight field. Let’s see how many nodes and edges exist in the network:

nx.info(G)
'Graph with...