24.07.2016 Views

www.allitebooks.com

Learning%20Data%20Mining%20with%20Python

Learning%20Data%20Mining%20with%20Python

SHOW MORE
SHOW LESS

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 Mining<br />

Visit http://networkx.lanl.gov/reference/drawing.html<br />

for more details on layouts in NetworkX. Although it adds some<br />

<strong>com</strong>plexity, the draw_graphviz option works quite well and is worth<br />

investigating for better visualizations. It is well worth considering in<br />

real-world uses.<br />

Let's use spring_layout for visualization:<br />

pos = nx.spring_layout(G)<br />

Using our pos layout, we can then position the nodes:<br />

nx.draw_networkx_nodes(G, pos)<br />

Next, we draw the edges. To get the weights, we iterate over the edges in the graph<br />

(in a specific order) and collect the weights:<br />

edgewidth = [ d['weight'] for (u,v,d) in G.edges(data=True)]<br />

We then draw the edges:<br />

nx.draw_networkx_edges(G, pos, width=edgewidth)<br />

The result will depend on your data, but it will typically show a graph with a large<br />

set of nodes connected quite strongly and a few nodes poorly connected to the rest<br />

of the network.<br />

[ 150 ]

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

Saved successfully!

Ooh no, something went wrong!