Code available via turi-code tutorials
In [1]:
import graphlab as gl
In [2]:
gl.canvas.set_target('ipynb') # use IPython Notebook output for GraphLab Canvas
In [3]:
vertices = gl.SFrame.read_csv('https://static.turi.com/datasets/bond/bond_vertices.csv')
edges = gl.SFrame.read_csv('https://static.turi.com/datasets/bond/bond_edges.csv')
In [4]:
# SFrame has a number of methods to explore and transform your data
vertices.show()
In [5]:
# this shows the summary of the edges SFrame
edges.show()
In [6]:
#Create a graph object
g = gl.SGraph()
In [7]:
#Add vertices and edges to this graph
# add some vertices in a dataflow-ish way
g = g.add_vertices(vertices=vertices, vid_field='name')
In [8]:
# more dataflow
g = g.add_edges(edges=edges, src_field='src', dst_field='dst')
In [9]:
# Show all the vertices
g.get_vertices()
Out[9]:
In [10]:
# Show all the edges
g.get_edges()
Out[10]:
In [11]:
# Get all the "friend" edges
g.get_edges(fields={'relation': 'friend'})
Out[11]:
In [12]:
#Apply the pagerank algorithm to our graph
pr = gl.pagerank.create(g)
In [14]:
pr.get('pagerank').topk(column_name='pagerank')
#We see, not unexpectedly, that James Bond is a very important person, and that bad guys aren't that popular...
Out[14]:
In [ ]: