10.11.2016 Views

Learning Data Mining with Python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Discovering Accounts to Follow Using Graph <strong>Mining</strong><br />

We can now visualize network using NetworkX's draw function, which uses<br />

matplotlib. To get the image in our notebook, we use the inline function on<br />

matplotlib and then call the draw function. The code is as follows:<br />

%matplotlib inline<br />

nx.draw(G)<br />

The results are a bit hard to make sense of; they show that there are some nodes <strong>with</strong><br />

few connections but many nodes <strong>with</strong> many connections:<br />

We can make the graph a bit bigger by using pyplot to handle the creation of the<br />

figure. To do that, we import pyplot, create a large figure, and then call NetworkX's<br />

draw function (NetworkX uses pyplot to draw its figures):<br />

from matplotlib import pyplot as plt<br />

plt.figure(3,figsize=(20,20))<br />

nx.draw(G, alpha=0.1, edge_color='b')<br />

The results are too big for a page here, but by making the graph bigger, an outline<br />

of how the graph appears can now be seen. In my graph, there was a major group<br />

of users all highly connected to each other, and most other users didn't have many<br />

connections at all. I've zoomed in on just the center of the network here and set the<br />

edge color to blue <strong>with</strong> a low alpha in the preceding code.<br />

[ 146 ]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!