Search code examples
pythonpandasmatrixrecommendation-engine

The best way to create a preference matrix


I have a matrix of 193,000 users and 16,000 movies. In addition, I have a matrix of those users' interactions with movies. Interactions

I want to create a preference matrix. If the user interacted with the movie, then on their intersection in the matrix put a score.

The interaction matrix contains 5000000 rows.

What is the best way to fill out the preference matrix?

Not what i did. idid

Preference matrix: d = pd.DataFrame(0, index = submission['user_id'].unique(), columns = interactions['item_id'].unique(), dtype = 'int8') matrix screen


Solution

  • you can try this

    df['has_watched'] = (df['watched_pct'] > 0).astype(int)
    df.pivot(index='user_id',columns='item_id',values='has_watched').fillna(0)