<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Introduction
Bipartite graphs are graphs that have two (bi-) partitions (-partite) of nodes. Nodes within each partition are not allowed to be connected to one another; rather, they can only be connected to nodes in the other partition.
Bipartite graphs can be useful for modelling relations between two sets of entities. We will explore the construction and analysis of bipartite graphs here.
Class Exercise
Earlier on in class, I had asked you to write down a list of cities for which you had visited. Now, I would like you to go about creating the bipartite graph of people & cities in the class. You may wish to get up from your seats to finish this last task.
Step1:  Explore the graph by going through the following algorithms
Step2:  Think about it...
Which metric is the better indicator of city popularity? How about how well-travelled an individual is?
Projection to a uni-partite graph
A bipartite graph can be projected down to a unipartite graph. The projection joins nodes of the same partition, based on their connections to nodes in the other partition. For example, if A is joined to 1 and B is joined to 1, then A and B will be joined in the uni-partite graph projection.
Exercise
Use the bipartite.projected_graph(G, nodes) function to construct the 'people' uni-partite projection.
Hint
<ASSISTANT_TASK:>
Python Code:
import networkx as nx
from networkx.algorithms import bipartite
# Initialize the city/person bipartite graph.
B = nx.Graph()
cities = ['Beijing', "Xi'an", 'Vancouver', 'San Francisco', 'Austin', 'Boston'] # populate a list of cities
people = ['Eric', 'Nan'] # populate a list of people's names 
B.add_nodes_from(cities, bipartite='cities')
B.add_nodes_from(people, bipartite='people')
edges = [("Eric", "Vancouver"), ("Nan", "Xi'an"), ("Eric", "San Francisco"), ("Nan", 'Boston'), ("Eric", 'Boston'), ("Nan", 'Beijing')] # populate a list of 2-tuples, which are the edges. Each 2-tuple should join one city with one person. 
B.add_edges_from(edges)
Explanation: Introduction
Bipartite graphs are graphs that have two (bi-) partitions (-partite) of nodes. Nodes within each partition are not allowed to be connected to one another; rather, they can only be connected to nodes in the other partition.
Bipartite graphs can be useful for modelling relations between two sets of entities. We will explore the construction and analysis of bipartite graphs here.
Class Exercise
Earlier on in class, I had asked you to write down a list of cities for which you had visited. Now, I would like you to go about creating the bipartite graph of people & cities in the class. You may wish to get up from your seats to finish this last task.
End of explanation
# Betweenness Centrality
bipartite.betweenness_centrality(B, cities)
# Degree Centrality
bipartite.degree_centrality(B, cities)
Explanation: Explore the graph by going through the following algorithms
End of explanation
bipartite.projected_graph(B, people).edges()
Explanation: Think about it...
Which metric is the better indicator of city popularity? How about how well-travelled an individual is?
Projection to a uni-partite graph
A bipartite graph can be projected down to a unipartite graph. The projection joins nodes of the same partition, based on their connections to nodes in the other partition. For example, if A is joined to 1 and B is joined to 1, then A and B will be joined in the uni-partite graph projection.
Exercise
Use the bipartite.projected_graph(G, nodes) function to construct the 'people' uni-partite projection.
Hint: bipartite.projected_graph(G, nodes) returns a NetworkX Graph or MultiGraph (with multiple edges between nodes).
End of explanation
<END_TASK>