Random graph.ipynb - Colab
Random graph.ipynb - Colab
ipynb - Colab
(𝑛, 𝑝) model
Erdos-Renyi model
n = 1000
p = 0.05
np.random.seed(42)
G = nx.fast_gnp_random_graph(n=n, p=p)
degrees = Series(dict(G.degree))
degrees[:5]
0 51
1 52
2 46
3 57
4 58
dtype: int64
32 1
33 2
34 3
35 5
36 3
37 15
38 13
39 16
40 26
41 17
Name: count, dtype: int64
vc.plot()
https://colab.research.google.com/drive/1FrpApfcdlwwxwv203cBFPIPos3muuR_A 1/4
12/4/24, 8:07 AM Random graph.ipynb - Colab
<Axes: >
Series(degrees).hist(bins=20)
<Axes: >
A better way to smooth things (when needed) is to do a Kernel Density Estimate (KDE).
df = DataFrame({'degrees':degrees})
sns.kdeplot(df)
https://colab.research.google.com/drive/1FrpApfcdlwwxwv203cBFPIPos3muuR_A 2/4
12/4/24, 8:07 AM Random graph.ipynb - Colab
<Axes: ylabel='Density'>
<Axes: ylabel='Density'>
CC = nx.clustering(G).values()
df['CC'] = CC
sns.kdeplot(df[['degree/(n-1)', 'CC']])
https://colab.research.google.com/drive/1FrpApfcdlwwxwv203cBFPIPos3muuR_A 3/4
12/4/24, 8:07 AM Random graph.ipynb - Colab
<Axes: ylabel='Density'>
https://colab.research.google.com/drive/1FrpApfcdlwwxwv203cBFPIPos3muuR_A 4/4