This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plt.scatter(degree, clustering) | |
plt.xlabel("Degree") | |
plt.ylabel("Clustering") | |
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
acc = nx.average_clustering(nx.Graph(G)) | |
acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Densidade:", nx.density(G)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Número de nós:", nx.number_of_nodes(G)) | |
print("Número de arestas:", nx.number_of_edges(G)) |
NewerOlder