유사도 찾기

Python으로 추천 엔진 만들기

Rob O'Callaghan

Director of Data

아이템 기반 추천

Python으로 추천 엔진 만들기

아이템 기반 추천

Python으로 추천 엔진 만들기

아이템 기반 추천

Python으로 추천 엔진 만들기

사용자 기반에서 아이템 기반으로

Python으로 추천 엔진 만들기

사용자 기반에서 아이템 기반으로

Python으로 추천 엔진 만들기

사용자 기반에서 아이템 기반으로

print(user_ratings_pivot):
          The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey                    
User_233               0.0                       0.0                     0.0
User_651               0.0                       0.5                    -0.5
User_965               0.5                      -0.5                     0.0
     ...               ...                       ...                     ...
book_ratings_pivot = user_ratings_pivot.T
print(book_ratings_pivot)
                  User_233                  User_651                User_965                    
The Great Gatsby       0.0                       0.0                     0.5
The Catcher in the Rye 0.0                       0.5                    -0.5
Fifty Shades of Grey   0.0                      -0.5                     0.0
                 ...   ...                       ...                     ...
Python으로 추천 엔진 만들기

코사인 유사도

book_ratings_pivot:

                  User_233                  User_651                User_965                    
The Great Gatsby       0.0                       0.0                     0.5
The Catcher in the Rye 0.0                       0.5                    -0.5
Fifty Shades of Grey   0.0                      -0.5                     0.0
                 ...   ...                       ...                     ...
Python으로 추천 엔진 만들기

코사인 유사도

cosine_similarity(                                                                    ,
                                                                               )
Python으로 추천 엔진 만들기

코사인 유사도

cosine_similarity(book_ratings_pivot.loc['Lord of the Rings', :]                      ,
                  book_ratings_pivot.loc['The Hobbit', :]                      )
Python으로 추천 엔진 만들기

코사인 유사도

cosine_similarity(book_ratings_pivot.loc['Lord of the Rings', :].values               ,
                  book_ratings_pivot.loc['The Hobbit', :].values               )
Python으로 추천 엔진 만들기

코사인 유사도

cosine_similarity(book_ratings_pivot.loc['Lord of the Rings', :].values.reshape(1, -1),
                  book_ratings_pivot.loc['The Hobbit', :].values.reshape(1, -1))
0.43
cosine_similarity(book_ratngs.loc['Lord of the Rings', :].values.reshape(1, -1),
                  book_ratngs.loc['Twilight', :].values.reshape(1, -1))
-0.64
Python으로 추천 엔진 만들기

코사인 유사도

similarities = cosine_similarity(book_ratings_pivot)

cosine_similarity_df = pd.DataFrame(book_ratings_pivot, index=book_ratings_pivot.index, columns=book_ratings_pivot.index)
cosine_similarity_df.head()
          The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey                    
The Great Gatsby       1.0                       0.0                    -0.3
The Catcher in the Rye 0.0                       1.0                    -0.5
Fifty Shades of Grey  -0.3                      -0.5                     1.0
                 ...   ...                       ...                     ...
Python으로 추천 엔진 만들기

코사인 유사도

cosine_similarity_series = cosine_similarity_df.loc['The Hobbit']

ordered_similarities = cosine_similarity_series.sort_values(ascending=False)
print(ordered_similarities)
The Hobbit         1.00
Lord of the Rings  0.43
The Silmarillion   0.37
...
Python으로 추천 엔진 만들기

연습해 봅시다!

Python으로 추천 엔진 만들기

Preparing Video For Download...