Collaborative filtering

การสร้าง Recommendation Engine ด้วย Python

Rob O'Callaghan

Director of Data

Collaborative filtering

การสร้าง Recommendation Engine ด้วย Python

Collaborative filtering

การสร้าง Recommendation Engine ด้วย Python

Collaborative filtering

การสร้าง Recommendation Engine ด้วย Python

การค้นหาผู้ใช้ที่คล้ายกัน

การสร้าง Recommendation Engine ด้วย Python

การค้นหาผู้ใช้ที่คล้ายกัน

การสร้าง Recommendation Engine ด้วย Python

การทำงานกับข้อมูลจริง

DataFrame user_ratings:

User Book Rating
User_233 The Great Gatsby 3.0
User_651 The Catcher in the Rye 5.0
User_131 The Lord of the Rings 3.0
User_965 The Great Gatsby 4.0
User_651 Fifty Shades of Grey 4.0
... ... ...
การสร้าง Recommendation Engine ด้วย Python

การ pivot ข้อมูล

user_ratings_pivot = user_ratings.pivot(index='User', 
                                        columns='Book',
                                        values='Rating')
print(user_ratings_pivot)
title     The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey
User                    
User_233               3.0                       NaN                     NaN
User_651               NaN                       5.0                     4.0
User_965               4.0                       3.0                     NaN
     ...               ...                       ...                     ...
การสร้าง Recommendation Engine ด้วย Python

ความเบาบางของข้อมูล

title     The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey
User                    
User_233               3.0                       NaN                     NaN
User_651               NaN                       5.0                     4.0
User_965               4.0                       3.0                     NaN
     ...               ...                       ...                     ...
print(user_ratings_pivot.dropna())
Empty DataFrame
Columns: ["The Great Gatsby", "The Catcher in the Rye", "Fifty Shades of Grey"]
Index: []
การสร้าง Recommendation Engine ด้วย Python

การเติมค่าที่หายไป

title     The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey
User                    
User_233               3.0                       NaN                     NaN
User_651               NaN                       5.0                     4.0
User_965               4.0                       3.0                     NaN
     ...               ...                       ...                     ...
print(user_ratings_pivot["User_651"].fillna(0))
User_651               0.0                       5.0                     4.0
การสร้าง Recommendation Engine ด้วย Python

การเติมค่าที่หายไป

การสร้าง Recommendation Engine ด้วย Python

การเติมค่าที่หายไป

avg_ratings = user_ratings_pivot.mean(axis=1)

user_ratings_pivot = user_ratings_pivot.sub(avg_ratings, axis=0)
print(user_ratings_pivot)
title     The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey
User                    
User_233               0.0                       NaN                     NaN
User_651               NaN                       0.5                    -0.5
User_965               0.5                      -0.5                     NaN
     ...               ...                       ...                     ...

การสร้าง Recommendation Engine ด้วย Python

การเติมค่าที่หายไป

user_ratings_pivot.fillna(0)
title     The Great Gatsby    The Catcher in the Rye    Fifty Shades of Grey
User                    
User_233               0.0                       0.0                     0.0
User_651               0.0                       0.5                    -0.5
User_965               0.5                      -0.5                     0.0
     ...               ...                       ...                     ...

การสร้าง Recommendation Engine ด้วย Python

มาฝึกกันเถอะ!

การสร้าง Recommendation Engine ด้วย Python

Preparing Video For Download...