<jupyter_start><jupyter_text>taking only userId, sexo and products into considerationuser_model = train_df.iloc[:,0:26]<jupyter_code>#user_item_sim = pd.DataFrame(index=user_model.index,columns=user_model.columns)
#retaining user IDs and sexo alone
user_item_sim.iloc[:,:2] = user_model.iloc[:,:2]
user_item_sim.head()
def getSimilarityScore(product_history, product_similarities):
   return sum(product_history*product_similarities)/sum(product_similarities)
#Test logic - 
#1) Get the product as input and get similarity matrix calculated with respect to other products 
#2) Get the neighbors of input product
#3) Get the history of products purchased
#4) Calculate the score by normalization - history * similarity /sum(similarity)
#a = item_sim.loc['ind_ahor_fin_ult1'].sort_values(ascending=False)[1:25]
#user_item_sim.head()
#b=item_neighbors.loc['ind_ahor_fin_ult1'][1:25]
#data_test.loc[0,b]
#user_item_sim.columns[2]
#incorporating above alogorithm as function - start j from 2, to skip user and sexo columns
#for i in range(0,len(user_item_sim.index)):
#    for j in range(2,len(user_item_sim.columns)):
#        user = user_item_sim.index[i]        
#        product = user_item_sim.columns[j]
 
#        if train_df.iloc[i][j] == 1:
#            user_item_sim.iloc[i][j] = 0
#        else:
#           product_top_names = item_neighbors.loc[product][1:10]
#           product_top_sims = item_sim.loc[product].sort_values(ascending=False)[1:10]
#           user_purchases = data_test.loc[user,product_top_names]
#
#            user_item_sim.iloc[i][j] = getSimilarityScore(user_purchases,product_top_sims)<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup