Challenge: Degree Centrality

Now for a challenge.

Which actor has directed the most movies?

Update and run these 2 GDS calls to find the actor that has directed the most *movies*.

  1. Create a graph projection using the gds.graph.project() procedure.

    Include Movie and Actor nodes with the DIRECTED relationship type.

    cypher
    CALL gds.graph.project(
        'actor-directors',
        ['??????', '??????'],
        '??????'
    )
  2. Run the degree centrality algorithm on the projected graph using the gds.degree.stream() procedure.

    Order the results to determine which actor has directed the most movies.

    cypher
    CALL gds.degree.stream('actor-directors')
    YIELD nodeId, score
    RETURN
      gds.util.asNode(nodeId).name AS name,
      score AS movies
    ORDER BY ?????? DESC

Enter the name of the actor (the answer is case sensitive):

  • ✓ Woody Allen

Hint

In the previous lesson, you used the following cypher to find the actors who have acted in the most movies:

cypher
CALL gds.graph.project(
  'proj',
  ['Actor','Movie'],
  'ACTED_IN'
  );

CALL gds.degree.stream('proj')
YIELD nodeId, score
RETURN
  gds.util.asNode(nodeId).name AS actorName,
  score AS numberOfMoviesActedIn
ORDER BY numberOfMoviesActedIn DESCENDING, actorName LIMIT 5

You can modify this to use the DIRECTED relationship to find actors who have directed the most films.

Solution

Woody Allen has directed the most movies in the database. To calculate this, you will need to create a graph projection.

cypher
Create the Projection
CALL gds.graph.project(
    'actor-directors',    // Projection name
    ['Actor', 'Movie'],  // Labels
    'DIRECTED'            // Relationship type
)

Next, run the degree centrality algorithm on the projected graph using the gds.degree.stream() procedure.

cypher
Run the degree centrality algorithm
CALL gds.degree.stream('actor-directors')
YIELD nodeId, score
RETURN
  gds.util.asNode(nodeId).name AS name,
  score AS movies
ORDER BY movies DESC

Summary

In this lesson you learned about centrality in GDS. We went over common use cases and how to run some of the most popular centrality algorithms in GDS.

In the next lesson, you will learn more about Path Finding Algorithms.