Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 910 Bytes
f123b98 71de22d f123b98 71de22d f123b98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import pandas as pd
import numpy as np
def calc_matches(filtered_df, project_df, similarity_matrix, top_x):
# matching project2 can be nay project
# indecies (rows) = project1
# columns = project2
# -> find matches
# filter out all row considering the filter
filtered_df_indecies_list = filtered_df.index
np.fill_diagonal(similarity_matrix, 0)
match_matrix = similarity_matrix[filtered_df_indecies_list]
# get row (project1) and column (project2) with highest similarity in filtered df
top_indices = np.unravel_index(np.argsort(match_matrix, axis=None)[-top_x:], match_matrix.shape)
# get the corresponding similarity values
top_values = match_matrix[top_indices]
p1_df = filtered_df.iloc[top_indices[0]]
p1_df["similarity"] = top_values
p2_df = project_df.iloc[top_indices[1]]
p2_df["similarity"] = top_values
return p1_df, p2_df
|