<jupyter_start><jupyter_text>Data preparation<jupyter_code>len(G.edges())
removed_edges = random.sample(list(G.edges()), 20)

for edge in removed_edges:
    G.remove_edge(edge[0], edge[1])
    
removed_edges
nx.draw(G, pos=pos, with_labels=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Algorithms  Jaccard coefficient<jupyter_code>preds = nx.jaccard_coefficient(G)

# convert iterator to series
edges = list()
scores = list()
for u, v, p in preds:
    edges.append((u, v))
    scores.append(p)
    jc = pd.Series(scores, edges)
    
jc.sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Adamic-Adar<jupyter_code>preds = nx.adamic_adar_index(G)

# convert iterator to series
edges = list()
scores = list()
for u, v, p in preds:
    edges.append((u, v))
    scores.append(p)
    aa = pd.Series(scores, edges)

aa.sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Preferential attachment<jupyter_code>preds = nx.preferential_attachment(G)

# convert iterator to series
edges = list()
scores = list()
for u, v, p in preds:
    edges.append((u, v))
    scores.append(p)
    pa = pd.Series(scores, edges)

pa.sort_values(ascending=False)<jupyter_output><empty_output><jupyter_text>Evaluation<jupyter_code># Jaccard coefficient
count = 0

for edge in list(jc.sort_values(ascending=False)[:20].index):
    if edge in removed_edges:
        count += 1

print('Accuracy: {}'.format(count/len(removed_edges)))
# Adamic-Adar
count = 0

for edge in list(aa.sort_values(ascending=False)[:20].index):
    if edge in removed_edges:
        count += 1

print('Accuracy: {}'.format(count/len(removed_edges)))
# Preferential attachment
count = 0

for edge in list(pa.sort_values(ascending=False)[:20].index):
    if edge in removed_edges:
        count += 1

print('Accuracy: {}'.format(count/len(removed_edges)))<jupyter_output>Accuracy: 0.0
{'fraction_non_alphanumeric': 0.13882978723404255, 'fraction_numerical': 0.009574468085106383, 'mean_word_length': 5.441780821917808, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '448292', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 726, 'n_tokens_neox': 696, 'n_words': 133, 'path': 'Link Prediction.ipynb', 'repo_name': 'IdeasLabUT/SBP-BRiMS-2021-NetworkX-Tutorial', 'size': '1880'}