【推荐系统】手把手带你学推荐系统 3 实现第一个推荐系统
【推荐系统】⚠️手把手带你学推荐系统 3⚠️ 实现第一个推荐系统.
·
概述
推荐系统 (Recommender System) 是一个信息过滤系统, 在很多领域都有广泛的使用. 推荐系统可以为用户提供个性化的产品, 挖掘用户的潜在需求. 从今天开始, 小白我就带大家来学习一下推荐系统方向的知识.

基于排名的推荐系统
基于排名的推荐系统是最容易实现的. 人们大概率会喜欢大家都喜欢的物品. 我们通过对物品进行排名, 取前 N 个物品对每个用户进行推荐.

代码实现
import pandas as pd
from sklearn.model_selection import train_test_split
def main():
data_merge = pd.read_csv("../data/data_merge.csv")
print(data_merge.head())
train, test = train_test_split(data_merge, test_size=0.4, random_state=0)
# Get a count of user_ids for each unique song as recommendation score
song = train.groupby(["title"])["user"].count()
song_df = pd.DataFrame(song)
song_df["title"] = song_df.index
song_df = song_df[["title", "user"]]
song_df.columns = ["title", "score"]
song_df.sort_values(by="score", ascending=False, inplace=True)
song_df['score'].rank(ascending=0, method='first')
print(song_df.head(10))
if __name__ == '__main__':
main()
输出结果:
0 d6589314c0a9bcbca4fee0c93b14bc402363afea ... 2004.0
1 d6589314c0a9bcbca4fee0c93b14bc402363afea ... 2007.0
2 d6589314c0a9bcbca4fee0c93b14bc402363afea ... 0.0
3 d6589314c0a9bcbca4fee0c93b14bc402363afea ... 1993.0
4 d6589314c0a9bcbca4fee0c93b14bc402363afea ... 0.0
[5 rows x 7 columns]
title score
title
Use Somebody Use Somebody 15264
Yellow Yellow 12950
Sehr kosmisch Sehr kosmisch 11034
Dog Days Are Over (Radio Edit) Dog Days Are Over (Radio Edit) 10663
You're The One You're The One 9634
Love Story Love Story 9326
Somebody To Love Somebody To Love 9275
Secrets Secrets 9077
Revelry Revelry 8962
Bring Me To Life Bring Me To Life 8937

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐


所有评论(0)