Graph differences over time
Now, you'll compute the graph differences over time! To look at the simplest case, here you'll use a window of (month, month + 1), and then keep track of the edges gained or lost over time. This exercise is preparation for the next exercise, in which you will visualize the changes over time.
Este ejercicio forma parte del curso
Intermediate Network Analysis in Python
Instrucciones del ejercicio
- Inside the
forloop:- Assign
Gs[i]tog1andGs[i + window]tog2. - Using
nx.difference()compute the difference betweeng2andg1. Append the result toadded. - Append the difference between
g1andg2toremoved.
- Assign
- Print
fractional_changes.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
import networkx as nx
# Instantiate a list of graphs that show edges added: added
added = []
# Instantiate a list of graphs that show edges removed: removed
removed = []
# Here's the fractional change over time
fractional_changes = []
window = 1
for i in range(len(Gs) - window):
g1 = Gs[____]
g2 = Gs[____ + ____]
# Compute graph difference here
added.append(____)
removed.append(____)
# Compute change in graph size over time
fractional_changes.append((len(g2.edges()) - len(g1.edges())) / len(g1.edges()))
# Print the fractional change
print(____)