Skip to content

Instantly share code, notes, and snippets.

@tanpengshi
Created November 16, 2020 12:50
Show Gist options
  • Save tanpengshi/983dbfb3cc8cc4bd69bdc9b82fde28d4 to your computer and use it in GitHub Desktop.
Save tanpengshi/983dbfb3cc8cc4bd69bdc9b82fde28d4 to your computer and use it in GitHub Desktop.
content_matrix = pd.DataFrame(content_matrix,columns=sorted(X_train['product_id'].unique()),index=sorted(X_train['user_id'].unique()))
content_df = content_matrix.stack().reset_index()
content_df = content_df.rename(columns={'level_0':'user_id','level_1':'product_id',0:'predicted_interaction'})
X_valid = X_valid.merge(content_df,on=['user_id','product_id'])
X_valid['predicted_purchase'] = X_valid['predicted_interaction'].apply(lambda x:1 if x>=0.5 else 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment