GithubHelp home page GithubHelp logo

dsc-node-centrality-lab-chicago-ds-080519's Introduction

Network Dynamics: Node Centrality - Lab

Introduction

In this lab, you'll get a chance to practice implementing and interpreting the centrality metrics discussed in the previous lesson by investigating the social network from Game of Thrones!

Objectives

You will be able to:

  • Compare and calculate degree, closeness, betweenness, and eigenvector centrality measures
  • Interpret characteristics of certain nodes based on their centrality metrics

Character Interaction Graph Data

A. J. Beveridge and J. Shan created a network from George R. Martin's "A song of ice and fire" by extracting relationships between characters of the story. The dataset is available at Github. Relationships between characters were formed every time a character's name appears within 15 words of another character. This was designed as an approximate metric for character's interactions with each other. The results of this simple analysis are quite profound and produce interesting visuals such as this graph:

With that, it's your turn to start investigating the most central characters!

import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style('darkgrid')
%matplotlib inline

Load the dataset

Start by loading the dataset as a pandas DataFrame. From this, you'll then create a network representation of the dataset using NetworkX.

The dataset is stored in the file 'asoiaf-all-edges.csv'.

# Load edges into dataframes
df = None

# Print the first five rows

Create a Graph

  • Instantiate an empty graph
  • Iterate through the data and create appropriate edges to the empty graph you instantiated above. Be sure to add the weight to each edge
# Create an empty graph instance
G = None

# Read edge lists into dataframes

Calculate Degree

To start the investigation of the most central characters in the books, calculate the degree centrality for each character. Then create a bar graph of the top 10 characters according to degree centrality.

# Your code here

Closeness Centrality

Repeat the above exercise for the top 10 characters according to closeness centrality.

# Your code here

Betweeness Centrality

Repeat the process one more time for betweeness centrality.

# Your code here

Putting it All Together

Great! Now put all of these metrics together along with eigenvector centrality. Combine all four metrics into a single dataframe for each character.

# Your code here

Identifying Key Players

While centrality can tell us a lot, you've also begun to see how certain individuals may not be the most central characters, but can be pivotal in the flow of information from one community to another. In the previous lesson, such nodes were labeled as 'bridges' acting as the intermediaries between two clusters. Try and identify such characters from this dataset.

# Your code here

Drawing the Graph

To visualize all of these relationships, draw a graph of the network.

# Your code here

Subsetting the Graph

As you can see, the above graph is undoubtedly noisy, making it difficult to discern any useful patterns. As such, reset the graph and only add edges whose weight is 75 or greater. From there, redraw the graph. To further help with the display, try using nx.spring_layout(G) for the position. To jazz it up, try and recolor those nodes which you identified as bridge or bottleneck nodes to communication.

# Your code here

Summary

In this lab, we looked at different centrality measures of the graph data for the ASIOF dataset. We also compared these measures to see how they correlate with each other. We also saw in practice, the difference between taking the weighted centrality measures and how it may effect the results.

dsc-node-centrality-lab-chicago-ds-080519's People

Contributors

shakeelraja avatar mathymitchell avatar loredirick avatar alexgriff avatar sumedh10 avatar cheffrey2000 avatar fpolchow avatar

Watchers

James Cloos avatar  avatar Mohawk Greene avatar Victoria Thevenot avatar Bernard Mordan avatar Otha avatar raza jafri avatar  avatar Joe Cardarelli avatar The Learn Team avatar Sophie DeBenedetto avatar  avatar  avatar Matt avatar Antoin avatar  avatar  avatar  avatar Amanda D'Avria avatar  avatar Ahmed avatar Nicole Kroese  avatar Kaeland Chatman avatar Lisa Jiang avatar Vicki Aubin avatar Maxwell Benton avatar  avatar  avatar

Forkers

phmutman

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.