<jupyter_start><jupyter_text>A dataset from Twitter: undirected graphhttp://networkrepository.com/rt-pol.phpAn undirected graph<jupyter_code>from statsmodels.distributions.empirical_distribution import ECDF
import networkx as nx
from statsmodels.distributions.empirical_distribution import ECDF
import numpy as np
import matplotlib.pyplot as plt
twitter=nx.read_edgelist('data/rt-pol.txt',delimiter=',',data=[('time',float)])
print('Numero di nodi: {}'.format(twitter.order()))
print('Numero di archi: {}'.format(twitter.size()))
nodes=list(twitter.nodes())
print(nodes[1])
print(twitter[nodes[1]])
# underscore. It is used to ignore values, given not using that in future code.
with open('data/example_underscore.txt') as f:
    #il file è:
    #12464,7349,1286901355,4
    #6820,12569,1287988962,5
    for line in f:
        source, destination, _, _= line.strip().split(',')
        print(source,destination,_,_)
        print(source,destination,_)
        print(source,destination)
twitter = nx.Graph()
with open('data/rt-pol.txt') as f:
    for line in f:
        source, destination, _= line.strip().split(',') #nodes are strings
        source, destination, _ = list(map(int,line.strip().split(','))) 
        # map (function, iterator) applies the function to each item of an iterable  
        #nodes are int 
        twitter.add_edge(int(source), int(destination))
print('Numero di nodi: {}'.format(twitter.order()))
print('Numero di archi: {}'.format(twitter.size()))
print(twitter[12464])
#print(twitter['12464'])

density = nx.density(twitter)
print('Density: {}'.format(density))<jupyter_output>Density: 0.00028173462530740065<jupyter_text>Degree analysis<jupyter_code>degree = list(dict(twitter.degree()).values())
print('Mean degree: {}'.format(np.mean(degree)))
print('Standard deviation: {}'.format(np.std(degree)))
print('Median: {}'.format(np.median(degree)))
print('Min: {}'.format(np.min(degree)))
print('Max: {}'.format(np.max(degree)))<jupyter_output>Mean degree: 5.2033567948023824
Standard deviation: 16.700531508711194
Median: 1.0
Min: 1
Max: 786<jupyter_text>ECDF in linear e logscale<jupyter_code># ECDF linear scale
cdf = ECDF(degree)
x = np.unique(degree)
y = cdf(x)
fig_cdf = plt.figure(figsize=(8,4))
axes = fig_cdf.gca()
axes.plot(x,y,marker='o',ms=6, linestyle='None')
axes.set_xlabel('Degree',size=20)
axes.set_ylabel('ECDF Facebook', size = 20)
# ECDF loglog scale
cdf = ECDF(degree)
x = np.unique(degree)
y = cdf(x)
fig_cdf = plt.figure(figsize=(8,4))
axes = fig_cdf.gca()
axes.loglog(x,y,marker='o',ms=8, linestyle='--')
axes.set_xlabel('Degree',size=20)
axes.set_ylabel('ECDF Facebook', size = 20)
# ECCDF
cdf = ECDF(degree)
x = np.unique(degree)
y = cdf(x)
fig_cdf = plt.figure(figsize=(8,4))
axes = fig_cdf.gca()
axes.loglog(x,1-y,marker='o',ms=8, linestyle='--')
axes.set_xlabel('Degree',size=20)
axes.set_ylabel('ECCDF Facebook', size = 20)
p = density
random_graph = nx.fast_gnp_random_graph(twitter.order(),p)
print('Number of nodes: {}'.format(random_graph.order()))
print('Number of links: {}'.format(random_graph.size()))
random_degree = list(dict(random_graph.degree()).values())
cdf = ECDF(degree)
x = np.unique(degree)
y = cdf(x)

cdf_random = ECDF(random_degree)
x_random = np.unique(random_degree)
y_random = cdf_random(x_random)

fig_cdf_fb = plt.figure(figsize=(8,4))
axes = fig_cdf_fb.gca()
axes.set_xscale('log')
axes.set_yscale('log')
axes.loglog(x,1-y,marker='o',ms=8, linestyle='--')
axes.loglog(x_random,1-y_random,marker='+',ms=10, linestyle='--')
axes.set_xlabel('Degree',size=20)
axes.set_ylabel('ECCDF', size = 20)<jupyter_output><empty_output><jupyter_text>Hubs<jupyter_code>percentile_99 = np.percentile(degree,99)
print(percentile_99)
hub_nodi = [k for k,v in dict(twitter.degree()).items() if v>= percentile_99]
print(len(hub_nodi))
print(list(hub_nodi))
# connectivity
print(nx.is_connected(twitter))
print(nx.number_connected_components(twitter))
#transitivity
transitivity=nx.transitivity(twitter)
print(transitivity)<jupyter_output>0.026800979372480153
{'fraction_non_alphanumeric': 0.17113760556383506, 'fraction_numerical': 0.04297069051167412, 'mean_word_length': 6.685114503816794, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '539400', 'license': 'MIT', 'n_tokens_mistral': 1638, 'n_tokens_neox': 1508, 'n_words': 269, 'path': 'Material/Example_Twitter.ipynb', 'repo_name': 'Andreaierardi/SocialNetworkAnalysis-project', 'size': '4026'}