1. Time based filtering
Great work with the previous set of exercises! We’re now going to continue with the case study,
2. Key concepts
by recapping how to do graph filtering (for edges, particularly), briefly introduce the use of the date time module in dealing with time series graphs, and review the use of nxviz for graph visualization.
3. Filtering edges
First off, let’s look at filtering edges, which is analogous to the filtering of nodes that you’ve done in the previous exercise. Let's say we have a graph G, which has two partitions, with 10 salespeople (numbered 0-9) and 10 customers (numbered 10-19).
Let's also say that along each edge, we keep a record of the number of times a salesperson has sold something to a customer. To filter edges to get back only sales relationships that involved greater than 10 occurrences, we can again use a list comprehension. In the case where we only want the 2-tuple of nodes involved in a transaction, we can use a list comprehension in which the result of each loop is just (u, v), but we use the metadata dictionary d to help us perform the filtering. Next up, let’s quickly review
4. Datetime
datetime. In the following exercises, you’ll need the datetime and timedelta objects from the datetime module in the Python standard library. If we have two datetime objects, created in the command above, where date1 is ‘2011-11-10’ and date2 is ‘2011-11-6’, they can be compared for inequality, such as date1 being greater than date2.
5. Graph visualization
Finally, let’s quickly recap the use of nxviz for visualizing graphs. We import circos from nxviz, and then pass the graph G into the circos function. We can also pass in other arguments to the function, such as grouping and coloring the nodes by the ‘bipartite’ keyword. After that, we use matplotlib dot pyplot’s show function to draw the aesthetically pleasing and informative graph to the screen.
6. Let's practice!
Now that we’ve reviewed the code needed for the exercises ahead, let’s get some practice!