Skip to content

Instantly share code, notes, and snippets.

Avatar

Davis Nascimento davisvictorns

  • Infoprime Sistemas
View GitHub Profile
View napf5.py
# degree sequence
count_sequence = sorted([data['count'] for node, data in list(G.nodes.data())], reverse=True)[1:]
fig, ax = plt.subplots(1,2,figsize=(8,4))
# all_data has information about count_sequence and the width of each bin
ax[0].hist(count_sequence)
ax[1].hist(count_sequence,bins=[x for x in range(80)])
ax[0].set_title("count Histogram")
View napf4.py
plt.style.use("default")
# degree sequence
degree_sequence = sorted([d for n, d in G.degree()], reverse=True)
fig, ax = plt.subplots(1,2,figsize=(8,4))
# all_data has information about degree_sequence and the width of each bin
ax[0].hist(degree_sequence)
ax[1].hist(degree_sequence,bins=[x for x in range(50)])
View napf3.py
edg_copy = edges.copy()
edge_with_weight = []
while len(edg_copy) > 0:
curr_edge = edg_copy[0]
equivalent_edges = []
# get the equivalent edges
# ('a', 'b') is equivalent to ('b', 'a') because it's not a directed connection
for edge in edg_copy:
is_different = False
for hashtag in edge:
View napf2.py
edges = []
nodes = []
for i, row in df.iterrows():
curr_hashtags = row['hashtags'].split(' ')
nodes += curr_hashtags
combinations = list(itertools.combinations(curr_hashtags, 2))
edges += combinations
nodes_unique = set(nodes)
View napf1.py
c = twitter.cursor(twitter.search, q='#7deSetPelaLiberdade', count=100, result_type='mixed', tweet_mode='extended')
tweets = []
count = 0
n_tweets = 30000
for tweet in c:
count += 1
tweets.append(tweet)
# each 100 tweets requires 1 request
# sleep after 180 requests
if count > 0 and count % (180 * 100) == 0:
View nx_scatter..py
plt.scatter(degree, clustering)
plt.xlabel("Degree")
plt.ylabel("Clustering")
plt.show()
View nx_graficos.py
degree = [G.degree(node) for node in G.nodes]
clustering = [nx.clustering(G, node) for node in G.nodes]
plt.hist(clustering)
plt.show()
plt.boxplot(clustering)
plt.show()
View nx_clustering.py
acc = nx.average_clustering(nx.Graph(G))
acc
View n_nos_arestas.py
print("Número de nós:", nx.number_of_nodes(G))
print("Número de arestas:", nx.number_of_edges(G))