Jan Mühlnikel
commited on
Commit
·
4ec3ad0
1
Parent(s):
7bccfb7
experiment
Browse files- functions/calc_matches.py +0 -25
functions/calc_matches.py
CHANGED
@@ -55,30 +55,6 @@ def calc_matches(filtered_df, project_df, similarity_matrix, top_x):
|
|
55 |
|
56 |
st.write(match_matrix.shape)
|
57 |
|
58 |
-
flattened_indices = np.argsort(match_matrix, axis=None)[-15:]
|
59 |
-
|
60 |
-
# Step 2: Convert flattened indices to 2D indices
|
61 |
-
row_indices, col_indices = np.unravel_index(flattened_indices, match_matrix.shape)
|
62 |
-
|
63 |
-
# Step 3: Extract the top 15 values and their corresponding indices
|
64 |
-
top_values = match_matrix[row_indices, col_indices]
|
65 |
-
top_indices = list(zip(row_indices, col_indices, top_values))
|
66 |
-
|
67 |
-
# Step 4: Sort the indices and values based on the values in descending order
|
68 |
-
top_15_indices_sorted = sorted(top_indices, key=lambda x: x[2], reverse=True)
|
69 |
-
|
70 |
-
# Display the results
|
71 |
-
for idx, (row, col, value) in enumerate(top_15_indices_sorted):
|
72 |
-
st.write(f"Rank {idx + 1}: Value = {value}, Row Index = {row}, Column Index = {col}")
|
73 |
-
|
74 |
-
p1_df = project_df.iloc[row_indices].copy()
|
75 |
-
p1_df['similarity'] = top_values
|
76 |
-
p2_df = project_df.iloc[col_indices].copy()
|
77 |
-
p2_df['similarity'] = top_values
|
78 |
-
|
79 |
-
return p1_df, p2_df
|
80 |
-
|
81 |
-
"""
|
82 |
# Get the linear indices of the top 'top_x' values
|
83 |
# (flattened index to handle the sparse matrix more effectively)
|
84 |
linear_indices = np.argsort(match_matrix.data)[-top_x:]
|
@@ -100,5 +76,4 @@ def calc_matches(filtered_df, project_df, similarity_matrix, top_x):
|
|
100 |
print("finished calc matches")
|
101 |
|
102 |
return p1_df, p2_df
|
103 |
-
"""
|
104 |
|
|
|
55 |
|
56 |
st.write(match_matrix.shape)
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
# Get the linear indices of the top 'top_x' values
|
59 |
# (flattened index to handle the sparse matrix more effectively)
|
60 |
linear_indices = np.argsort(match_matrix.data)[-top_x:]
|
|
|
76 |
print("finished calc matches")
|
77 |
|
78 |
return p1_df, p2_df
|
|
|
79 |
|