Găsirea similarităților

Construirea motoarelor de recomandare în Python

Rob O'Callaghan

Director of Data

Recomandări bazate pe elemente

Construirea motoarelor de recomandare în Python

Recomandări bazate pe elemente

Construirea motoarelor de recomandare în Python

Recomandări bazate pe elemente

Construirea motoarelor de recomandare în Python

De la utilizator la element

Construirea motoarelor de recomandare în Python

De la utilizator la element

Construirea motoarelor de recomandare în Python

De la utilizator la element

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
                 ...   ...                       ...                     ...
Construirea motoarelor de recomandare în Python

Similarități cosinus

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
                 ...   ...                       ...                     ...
Construirea motoarelor de recomandare în Python

Similarități cosinus

cosine_similarity(                                                                    ,
                                                                               )
Construirea motoarelor de recomandare în Python

Similarități cosinus

cosine_similarity(book_ratings_pivot.loc['Lord of the Rings', :]                      ,
                  book_ratings_pivot.loc['The Hobbit', :]                      )
Construirea motoarelor de recomandare în Python

Similarități cosinus

cosine_similarity(book_ratings_pivot.loc['Lord of the Rings', :].values               ,
                  book_ratings_pivot.loc['The Hobbit', :].values               )
Construirea motoarelor de recomandare în Python

Similarități cosinus

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
Construirea motoarelor de recomandare în Python

Similarități cosinus

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
                 ...   ...                       ...                     ...
Construirea motoarelor de recomandare în Python

Similarități cosinus

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
...
Construirea motoarelor de recomandare în Python

Să exersăm!

Construirea motoarelor de recomandare în Python

Preparing Video For Download...