python 熊猫贝叶斯评级

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 熊猫贝叶斯评级相关的知识,希望对你有一定的参考价值。

import pandas as pd
    
# Movie ratings from movielens    
df = pd.read_csv('https://raw.githubusercontent.com/warriorkitty/orientlens/master/movielens/ratings.csv')

# Group by movieId and aggregate the mean and the count of each
gb = df.groupby(by=['movieId'], as_index=False).agg({'rating': ['mean', 'count']})

# The mean vote across the whole report
C = float(gb['rating']['mean'].mean())

# The minimum count of votes
m = 100

# Calculate the weighted ratings for each movie
gb['bayes_rating'] = ((gb['rating']['count'] / (gb['rating']['count'] + m )) * gb['rating']['mean'])\
    + (m / ( gb['rating']['count'] + m)) * C

# Show the best movies
gb.sort_values(by='bayes_rating', ascending=False, inplace=True)
 
# Top 10
gb.head(10)

以上是关于python 熊猫贝叶斯评级的主要内容,如果未能解决你的问题,请参考以下文章

如何为二进制评级系统实现贝叶斯平均算法

推荐系统笔记:基于贝叶斯的协同过滤

朴素贝叶斯算法简介及python代码实现分析

Python----朴素贝叶斯

朴素贝叶斯算法(python)

朴素贝叶斯分类算法介绍及python代码实现案例