<jupyter_start><jupyter_text>parameters from make snapshots<jupyter_code>vertex_metrics = ['indegree', 'outdegree', 'degree',
                  'd_pagerank','u_pagerank',
                  'authorities', 'hubs',
                  #'d_eigen', 'u_eigen', # d_eigen is being problematic
                  'u_eigen',
                  'd_betweenness', 'u_betweenness',
                  'd_closeness', 'u_closeness']

# add recent citations
vertex_metrics += ['recentcite_' + str(t) for t in np.arange(1, 10 + 1)]
vertex_metrics += ['recentcite_' + str(t) for t in [15, 20, 25, 30, 35, 40]]

vertex_metrics += ['age', 'similarity']

active_years = range(1900, 2015 + 1)<jupyter_output><empty_output><jupyter_text>test parameters<jupyter_code>test_seed = 4332,
num_test_cases = 10

test_cases = get_test_cases(G, active_years, num_test_cases, seed=test_seed)<jupyter_output><empty_output><jupyter_text>rank by sorting<jupyter_code>%%time 
rankloss_sort = get_rankscores_sort(G, test_cases, vertex_metrics, subnet_dir)
MRS_sort = rankloss_sort['MRS'].mean().sort_values()
RR_sort = rankloss_sort['RR'].mean().sort_values()
PAK100_sort = rankloss_sort['PAK100'].mean().sort_values()
PAK1000_sort = rankloss_sort['PAK1000'].mean().sort_values()

MRS_sort
# histogram of scores

# plt.figure(figsize=[20, 20])
# k = 1
# h = ceil(scores_sort.shape[1] / 4.0)
# for c in sort_mean.index:
#     plt.subplot(h, 4, k)
#     plt.hist(scores_sort[c])
#     plt.xlabel(c)
    
#     k += 1<jupyter_output><empty_output><jupyter_text>Match<jupyter_code>num_to_keep = 5000
%%time
rankloss_match = get_rankscores_match(G, test_cases, vertex_metrics, subnet_dir, num_to_keep)
MRS_match = rankloss_match['MRS'].mean().sort_values()
RR_match = rankloss_match['RR'].mean().sort_values()
PAK100_match = rankloss_match['PAK100'].mean().sort_values()
PAK1000_match = rankloss_match['PAK1000'].mean().sort_values()

MRS_match<jupyter_output><empty_output><jupyter_text>make training data for logistic regression<jupyter_code># how many abset edges to add
num_absent_edges = len(G.es)
seed_edge_df = 32432

# how to normalize yearly metrics
metric_normalization = 'mean'

feature_transform = 'poly2'
%%time 

# make_tr_edge_df(G, subnet_dir,
#                 active_years, num_absent_edges,
#                 vertex_metrics, metric_normalization,
#                 seed=seed_edge_df)<jupyter_output>CPU times: user 2 µs, sys: 3 µs, total: 5 µs
Wall time: 5.96 µs<jupyter_text>rank by logistic regression<jupyter_code>%%time
rankloss_LR, LogRegs = get_rankscores_LR(G, test_cases, vertex_metrics, subnet_dir,
                                         metric_normalization, feature_transform)              
MRS_LR = rankloss_LR['MRS'].mean().sort_values()
RR_LR = rankloss_LR['RR'].mean().sort_values()
PAK100_LR = rankloss_LR['PAK100'].mean().sort_values()
PAK1000_LR = rankloss_LR['PAK1000'].mean().sort_values()

MRS_LR<jupyter_output><empty_output><jupyter_text>cache results<jupyter_code>with open(subnet_dir + 'results/rankloss_sort.p', 'wb') as fp:
    pickle.dump(rankloss_sort, fp)
    
with open(subnet_dir + 'results/rankloss_match.p', 'wb') as fp:
    pickle.dump(rankloss_match, fp)

with open(subnet_dir + 'results/rankloss_LR.p', 'wb') as fp:
    pickle.dump(rankloss_LR, fp)
    
with open(subnet_dir + 'results/LogRegs.p', 'wb') as fp:
    pickle.dump(LogRegs, fp)
rankloss_sort = pickle.load( open( subnet_dir + 'results/rankloss_sort.p', "rb" ) )
rankloss_match = pickle.load( open( subnet_dir + 'results/rankloss_match.p', "rb" ) )
rankloss_LR = pickle.load( open( subnet_dir + 'results/rankloss_LR.p', "rb" ) )
LogRegs = pickle.load( open( subnet_dir + 'results/LogRegs.p', "rb" ) )
# scores_sort.to_csv(subnet_dir + 'results/scores_sort.csv', index=True)
# scores_search.to_csv(subnet_dir + 'results/scores_search.csv', index=True)
# scores_LR.to_csv(subnet_dir + 'results/scores_LR.csv', index=True)
# scores_LR_logloss.to_csv(subnet_dir + 'results/scores_LR_logloss.csv', index=True)

# with open(subnet_dir + 'results/LogRegs.p', 'wb') as fp:
#     pickle.dump(LogRegs, fp)<jupyter_output><empty_output><jupyter_text>results<jupyter_code>df_metric = pd.DataFrame(columns=['sort', 'match', 'LR'],
                         index = range(len(vertex_metrics)))

df_metric['sort'] = MRS_sort.index
df_metric['match'] = MRS_match.index
df_metric['LR'] = MRS_LR.index

df_metric
rankscores = pd.DataFrame(columns=['sort', 'match', 'LR'],
                         index = vertex_metrics)

rankscores['sort'] = MRS_sort
rankscores['match'] = MRS_match
rankscores['LR'] = MRS_LR
rankscores.sort_values(by='sort', ascending=True)
rs_ranking = rankscores.apply(lambda c: rankdata(c))
rs_ranking.sort_values(by='sort')<jupyter_output><empty_output><jupyter_text>experiment function<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14151925078043703, 'fraction_numerical': 0.02060353798126951, 'mean_word_length': 5.0452830188679245, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '284860', 'license': 'MIT', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1777, 'n_words': 289, 'path': 'vertex_metrics_experiment/rankscores_scotus.ipynb', 'repo_name': 'wethepeopleonline/law-net', 'size': '4805'}