赞
踩
博主介绍:✌全网粉丝10W+,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业毕业设计项目实战6年之久,选择我们就是选择放心、选择安心毕业✌感兴趣的可以先收藏起来,点赞、关注不迷路✌
毕业设计:2023-2024年计算机专业毕业设计选题汇总(建议收藏)
毕业设计:2023-2024年最新最全计算机专业毕设选题推荐汇总
技术栈:
Python语言、Django框架、用户画像+基于用户的协同过滤推荐算法、数据集是Last.fm Dataset 歌曲数据集
(1)系统首页
(2)给喜欢的音乐打标签
(3)播放音乐
(4)用户画像、用户选择音乐标签
(5)后台数据管理
(6)注册登录界面
随着我国互联网技术的飞速发展,信息量开始迅速猛增,在音乐方面,传统的实体专辑远远不如网络数字音乐的发展迅猛。如今,网络上新歌层出不穷,面对成千上万还没有听过的歌曲,用户想要从中找出自己喜欢的歌曲太过困难,也会浪费太多的时间。依靠传统的搜索方式来寻找自己感兴趣的歌曲已经无法满足用户的需求,个性化的推荐系统应运而生。
协同过滤算法因其实现简单、方便应用到产品中等特点在推荐系统中被广泛使用,而本文主要讨论的是协同过滤算法中的基于用户的算法。系统会依据用户对歌曲的一些操作行为,比如将喜欢的歌曲加入收藏的歌单等等,然后使用基于用户的协同过滤推荐算法,找出与想推荐用户相类似的邻居用户,通过分析邻居用户有没有某音乐产生兴趣偏好从而预测目标用户可能感兴趣的歌曲,进行个性化的推荐,这样用户在选择判断的时候能减少很多的时间,也可以解决一些用户的选择困难症,优化用户的听歌体验。本文的数据集是Last.fm Dataset 歌曲数据集,研究的项目是基于Python 语言开发,采用Python3实现各项功能,采取sqlite3数据库进行数据的存储,通过Django框架连接系统的前、后端。
关键词: 音乐推荐系统;协同过滤算法; Python编程技术;数据库
from django.contrib import messages from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.http import HttpResponseRedirect from django.core.paginator import Paginator from django.shortcuts import render, get_object_or_404 from .models import Music, UserProfile from .recommend import build_df, build_recommend from .subscribe import build_genre_ids, build_languages from .decorators import cold_boot current_play = None current_recommend = [] def home(request): return all(request) def sign_up(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') if User.objects.filter(username=username).exists(): messages.add_message(request, messages.ERROR, '用户名已存在!') else: user_obj = User.objects.create_user(username=username, password=password) UserProfile.objects.create(user=user_obj) messages.add_message(request, messages.SUCCESS, '注册成功!') return HttpResponseRedirect('/') return render(request, 'sign_up.html') def sign_in(request): if request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = authenticate(request, username=username, password=password) if user is not None: login(request, user=user) messages.success(request, '登录成功') return HttpResponseRedirect('/') else: messages.add_message(request, messages.ERROR, '用户名或密码错误!') return render(request, 'sign_in.html') @login_required(login_url='/sign_in') def user_logout(request): logout(request) messages.info(request, '退出登录') return HttpResponseRedirect('/') @cold_boot def all(request): page_number = request.GET.get('page', 1) queryset = Music.objects.all() paginator = Paginator(queryset, 20) musics = paginator.page(page_number) context = { 'musics': musics, 'user_likes': [], 'user_dislikes': [] } if request.user.is_authenticated: user_profile = UserProfile.objects.filter(user=request.user) if user_profile.exists(): user_profile = user_profile.first() context['user_likes'] = user_profile.likes.all() context['user_dislikes'] = user_profile.dislikes.all() return render(request, 'list.html', context) @login_required(login_url='/sign_in') @cold_boot def recommend(request): page_number = request.GET.get('page', 1) recommend_set = build_recommend(request, request.user) paginator = Paginator(recommend_set, 20) musics = paginator.page(page_number) context = { 'musics': musics, 'user_likes': [], 'user_dislikes': [] } user_profile = UserProfile.objects.filter(user=request.user) if user_profile.exists(): user_profile = user_profile.first() context['user_likes'] = user_profile.likes.all() context['user_dislikes'] = user_profile.dislikes.all() return render(request, 'list.html', context) @login_required(login_url='/sign_in') def like(request, pk: int): user_obj = UserProfile.objects.get(user=request.user) music_obj = get_object_or_404(Music.objects.all(), pk=pk) user_obj.likes.add(music_obj) user_obj.dislikes.remove(music_obj) messages.add_message(request, messages.INFO, '已经添加到我喜欢') redirect_url = request.GET.get('from', '/') if 'action' in request.GET: redirect_url += f'&action={request.GET["action"]}' return HttpResponseRedirect(redirect_url) @login_required(login_url='/sign_in') def dislike(request, pk: int): user_obj = UserProfile.objects.get(user=request.user) music_obj = get_object_or_404(Music.objects.all(), pk=pk) user_obj.dislikes.add(music_obj) user_obj.likes.remove(music_obj) messages.add_message(request, messages.INFO, '已经添加到我不喜欢') redirect_url = request.GET.get('from', '/') if 'action' in request.GET: redirect_url += f'&action={request.GET["action"]}' return HttpResponseRedirect(redirect_url) def play(request, pk: int = 0): global current_play if pk > 0: music_obj = Music.objects.filter(pk=pk) if music_obj.exists(): current_play = music_obj.first() if current_play is None: messages.error(request, '当前没有正在播放的音乐') return HttpResponseRedirect('/') return render(request, 'play.html', context={ 'music': current_play }) @login_required(login_url='/sign_in') def user_center(request): user_profile = UserProfile.objects.filter(user=request.user) if user_profile.exists(): profile_obj: UserProfile = user_profile.first() else: messages.error(request, '找不到用户资料,请重新登录') logout(request) return HttpResponseRedirect('/') if request.method == 'POST': genres = request.POST.getlist('genres', '') languages = request.POST.getlist('languages', '') profile_obj.first_run = False if len(genres) > 0: profile_obj.genre_subscribe = ','.join(genres) profile_obj.save() messages.success(request, '修改流派订阅成功!') elif not profile_obj.first_run: profile_obj.genre_subscribe = '' profile_obj.save() messages.success(request, '修改流派订阅成功!') if len(languages) > 0: profile_obj.language_subscribe = ','.join(languages) profile_obj.save() messages.success(request, '修改语言订阅成功!') elif not profile_obj.first_run: profile_obj.language_subscribe = '' profile_obj.save() messages.success(request, '修改语言订阅成功!') context = { 'user_likes': profile_obj.likes.all(), 'user_dislikes': profile_obj.dislikes.all(), 'genres': build_genre_ids(), 'languages': build_languages(), 'genre_subscribe': profile_obj.genre_subscribe.split(','), 'language_subscribe': [] } # 去除空字符 for lang in profile_obj.language_subscribe.split(','): lang = lang.strip() context['language_subscribe'].append(lang) return render(request, 'user.html', context=context) def search(request): if 'keyword' not in request.GET: messages.error(request, '请输入搜索关键词') return HttpResponseRedirect('/') keyword = request.GET.get('keyword') action = request.GET.get('action') musics = [] if action == 'song_name': musics = Music.objects.filter(song_name__contains=keyword) if action == 'artist_name': musics = Music.objects.filter(artist_name__contains=keyword) messages.info(request, f'搜索关键词:{keyword},找到 {len(musics)} 首音乐') context = { 'musics': musics, 'user_likes': [], 'user_dislikes': [] } if request.user.is_authenticated: user_profile = UserProfile.objects.filter(user=request.user) if user_profile.exists(): user_profile = user_profile.first() context['user_likes'] = user_profile.likes.all() context['user_dislikes'] = user_profile.dislikes.all() return render(request, 'list.html', context)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。