Network Analysis Flashcards
Data Tools and Techniques
- Basic Data Manipulation and Analysis
- Data Mining
- Machine Learning
- Data Visualization
- Data Collection and Preparation
Over a specific type of data
Performing well-defined computations or asking well-defined questions (“queries”)
Basic Data Manipulation and Analysis
Looking for patterns in data
Data Mining
Using data to make inferences or predictions
Machine Learning
Graphical depiction of data
Data Visualization
A _ is a collection of nodes (or vertices) and edges (or links) that represent relationships or connections between entities.
Network (graph)
note: dash in code (-) is actually underscore(_)
Load graph from CSV file with no header
f = open(‘Friends.csv’)
G = nx.read_edgelist(f, delimiter=’,’, nodetype=str)
print(G)
Graph with 10 nodes and 15 edges
Display graph
nx.draw(G, with-labels = True , node-size = 1500, node-color = ‘c’)
Displays graph
~
If Directed Graph
f = open(‘Follows.csv’)
D = nx.read_edgelist(f, delimiter=’,’, nodetype=str, create-using=nx.DiGraph())
print(D)
nx.draw(D, with-labels=True, node-size=1500, arrows=True, node-color=’c’)
~>
DiGraph with 10 nodes and 18 edges
Displays graph
The _ represent entities in a network.
Nodes (or vertices)
Iterating through nodes of the graph
for n in G:
print(n)
~>
Aaron
Chris
Emma
...
The _ represent connections or relationships between nodes.
Edges (or links)
Friends lists
for n in G:
print(n, ‘is friends with:’)
friends = G.neighbors(n) # friends is iterator
for f in friends:
print(‘ ‘, f)
~>
Aaron is friends with:
Chris
Emma
Chris is friends with:
Aaron
Drew
...
Friends lists v2
for n in G:
print(n, ‘is friends with:’, list(G.neighbors(n)))
~>
Aaron is friends with: ['Chris', 'Emma']
Chris is friends with: ['Aaron', 'Drew']
...
The _ is the number of edges connected to a node.
Degree
Degree
numfriends = G.degree
print(numfriends)
print(“”)
for n in numfriends:
print(n[0], ‘has’, n[1], ‘friends’)
print(“”)
~
Or can treat list of pairs like a dictionary
for n in G:
print(n, ‘has’, numfriends[n], ‘friends’)
~>
Aaron has 4 friends
Chris has 5 friends
...
Edges can be _ or _.
Directed, Undirected
Undirected edges imply a mutual connection (e.g., friendships), while directed edges indicate a one-way relationship (e.g., following someone on social media).
It is the study of the structure and behavior of networks, focusing on the relationships between nodes (entities) and edges (connections).
Network Analysis
It helps to understand patterns, connectivity, and dynamics within complex systems, such as social networks, communication systems, or transportation grids, using mathematical and computational techniques.
Network examples
- Flight Routes
- Disease Transmission
- Food Chain
- Criminal Networks
- Science Citations
- Retweets
- Facebook Friends
Other Examples
* Electricity grid + other civil infrastructure
* The brain + other biological structures
* Organizations and organizational behavior
* Spread of memes, other social phenomena
* And many, many more…
In network analysis, the _ of a graph measures how many edges are present in the graph compared to the maximum possible number of edges. It is a ratio that reflects the level of connectivity between nodes.
Density
A density of 1 means full connection while near 0 indicates sparse links
Density of graph
numnodes = G.number-of-nodes()
numedges = G.number-of-edges()
possedges = G.number-of-nodes() * (G.number-of-nodes() - 1)
print(‘Number of nodes:’, numnodes)
print(‘Number of edges:’, numedges)
print(‘Possible edges:’, possedges)
print(‘Density (edges divided by possible edges):’, numedges/possedges)
~>
Number of nodes: 10
Number of edges: 15
Possible edges: 90
Density (edges divided by possible edges): 0.16666666666666666
Using density function
print(‘Using density function:’, nx.density(G))
~>
Using density function: 0.3333333333333333
What is the formula for graph density?
Density = number of edges / number of possible edges
[Directed] Possibleedges = n(n−1)
[Undirected] Possibleedges = (n(n−1)) / 2
where n is the number of nodes
The _ in a graph is the minimum number of edges required to travel between two nodes in the network.
Shortest path
Shortest path (or shortest distance) between given pair of nodes
“Six degrees of separation”
(Four in Facebook)
Overall average shortest distance
print(‘Average shortest distance:’, nx.average-shortest-path-length(G))
~>
Average shortest distance: 2.022222222222222