如今协同过滤等传统推荐算法被广泛用于推荐,但也存在冷启动、矩阵稀疏等问题,本项目用深度学习来实现电影推荐,核心算法主要参考了https://blog.csdn.net/chengcheng1394/article/details/78820529,基于tensorflow和卷积神级网络来实现个性化电影推荐。web端用django来进行开发。
实现效果 1.算法运行结果 (1)输入电影,推荐相似的电影以及看过的人还喜欢的电影 (2)输入用户信息,推荐其喜爱的电影 2.系统界面 登录页面 电影推荐 主要代码 网络模型代码这里就不放了,可以参考https://blog.csdn.net/chengcheng1394/article/details/78820529 说说django的一些主要代码 urls.py配置路由 settings.py 配置数据库 登录功能
def login(request):
if request.method == 'GET':
return render(request, 'login.html')
else:
u = request.POST.get('user')
p = request.POST.get('pwd')
if u and p:
c = User.objects.filter(username=u,password=p).count()
if c >= 1:
cur_id = User.objects.get(username=u, password=p).id
return redirect('/mess/?user_id='+str(cur_id))
else:
return render(request, 'login.html', {'msg': '账号密码错误'})
else:
return render(request, 'login.html', {'msg': '请输入正确的账号密码'})
推荐喜欢的电影
def like(request):
user_id = request.GET.get('user_id')
my_user = models.User.objects.get(id=user_id)
global global_model
model = global_model
print('-------正在推荐--------', user_id)
list_like_movies_names, list_like_movies_ids = model.recommend_your_movie(int(user_id))
print('你喜欢的电影:', list_like_movies_names)
print('你喜欢的电影id:', list_like_movies_ids)
list_dict_like = []
for i in list_like_movies_names[:6]:
list_dict_like.append(utils.movie_dic(i))
for i in range(len(list_dict_like)):
list_dict_like[i]['movie_id'] = int(list_like_movies_ids[i])
print('相似电影列表:', list_dict_like)
context = {}
context['list_dict_like'] = list_dict_like
context['my_user'] = my_user
return render(request, 'like.html', context)
推荐同类型的电影和看过的人喜欢的电影
def index(request):
movie_id = request.GET.get('movie_id')
global global_model
model = global_model
print('-------正在推荐--------', movie_id)
choice_movie_name, list_same_movies_names, list_pepole_like_movies_names, list_same_movies_ids, list_pepole_like_movies_ids = model.recommend_by_movie(
int(movie_id))
print('选择电影:', choice_movie_name)
print('相似的电影:', list_same_movies_names)
print('喜欢这个电影的人还喜欢:', list_pepole_like_movies_names)
print('相似的电影id:', list_same_movies_ids)
print('喜欢这个电影的人还喜欢id:', list_pepole_like_movies_ids)
list_dict_choice = []
for i in choice_movie_name:
list_dict_choice.append(utils.movie_dic(i))
list_dict_choice[0]['movie_id'] = movie_id
print('选择电影列表:', list_dict_choice)
list_dict_same = []
for i in list_same_movies_names:
list_dict_same.append(utils.movie_dic(i))
for i in range(len(list_dict_same)):
list_dict_same[i]['movie_id'] = int(list_same_movies_ids[i])
print('相似电影列表:', list_dict_same)
list_dict_otherlike = []
for i in list_pepole_like_movies_names:
list_dict_otherlike.append(utils.movie_dic(i))
for i in range(len(list_dict_otherlike)):
list_dict_otherlike[i]['movie_id'] = int(list_pepole_like_movies_ids[i])
print('喜欢这个电影的人还喜欢列表:', list_dict_otherlike)
context = {}
context['list_dict_choice'] = list_dict_choice
context['list_dict_same'] = list_dict_same
context['list_dict_otherlike'] = list_dict_otherlike
return render(request, 'index.html', context)
|