'Using cosine_similarity function on Python to make Recommender System

I'm trying to make recommendation system by rating's of music type. Contend based recommendation system.


import numpy as np
import pandas as pd
from sklearn.metrics.pairwise import cosine_similarity

a = [[3],[8],[0],[0],[11]]
b = [[1],[1],[0],[0],[1]]]
ap = pd.DataFrame(a, index=['Sonata','Etudes','Waltzes','Nocturnes','Marches'],columns=['ratings'])
bp = pd.DataFrame(b, index=['Sonata','Etudes','Waltzes','Nocturnes','Marches'],columns=['watched movie?'])



and this code's result returns

enter image description here

Input user ratings

enter image description here

Movies Matrix

But if i use cosine_similarity function like ->

from sklearn.metrics.pairwise import cosine_similarity
pd.DataFrame(cosine_similarity(a, b),columns=['A','B','c','d','e'], index=['Sonata','Etudes','Waltzes','Nocturnes','Marches'])

(the reason i added B c d e column is , error says i need 5 columns and 5 indexes.) this code returns

enter image description here

I want only result of cosine_similarity function of A table and B table 's rating but result can only show on 5x5 table and there is only 0 or 1 value.

My expected result was like this ==>>>

enter image description here

How should i change my code if i want to build recommand system with using cosine_similarity?

i'm watching this youtube video now...

https://www.youtube.com/watch?v=YMZmLx-AUvY&ab_channel=MyCourse

and this is the logic i'm refer to.

enter image description here enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source