|
import pandas as pd |
|
import numpy as np |
|
from scipy.sparse import csr_matrix, lil_matrix |
|
import streamlit as st |
|
|
|
|
|
def calc_matches(filtered_df, project_df, similarity_matrix, top_x): |
|
st.write(filtered_df.shape) |
|
st.write(project_df.shape) |
|
st.write(similarity_matrix.shape) |
|
|
|
|
|
|
|
|
|
|
|
|
|
filtered_df_indices = filtered_df.index.to_list() |
|
project_df_indices = project_df.index.to_list() |
|
|
|
|
|
filtered_df_index_map = {i: index for i, index in enumerate(filtered_df_indices)} |
|
project_df_index_map = {i: index for i, index in enumerate(project_df_indices)} |
|
|
|
|
|
match_matrix = similarity_matrix[filtered_df_indices, :][:, project_df_indices] |
|
|
|
st.write(match_matrix.shape) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flat_indices = np.argpartition(match_matrix.flatten(), -3)[-3:] |
|
|
|
|
|
row_indices, col_indices = np.unravel_index(flat_indices, match_matrix.shape) |
|
|
|
|
|
top_values = match_matrix[row_indices, col_indices] |
|
|
|
top_filtered_df_indices = [filtered_df_index_map[i] for i in col_indices] |
|
top_project_df_indices = [project_df_index_map[i] for i in row_indices] |
|
|
|
st.write(top_filtered_df_indices) |
|
|
|
|
|
p1_df = filtered_df.loc[top_filtered_df_indices].copy() |
|
p1_df['similarity'] = top_values |
|
|
|
p2_df = project_df.loc[top_project_df_indices].copy() |
|
p2_df['similarity'] = top_values |
|
print("finished calc matches") |
|
|
|
return p1_df, p2_df |
|
|
|
|