博舍

基于python实现的电影推荐系统 人工智能 推荐系统

基于python实现的电影推荐系统

源码下载http://www.byamd.xyz/hui-zong-1/设计总说明

本文设计了一个个性化电影推荐系统.众所周知,现在电影资源是网络资源的重要组成部分,随着网络上电影资源的数量越来越庞大,设计电影个性化推荐系统迫在眉睫.所以本文旨在为每一个用户推荐与其兴趣爱好契合度较高的电影.

论文首先阐述推荐系统的研究现状以及意义,随后介绍了相关的推荐算法,重点介绍协同过滤算法,并对系统实现所需技术进行了研究,接着介绍了整个推荐系统的实现,最后对整个项目进行了回顾与总结.

本系统包含电影前端展示界面、电影评分板块、推荐算法的实现以及后端数据库的设计.其中实现推荐算法是整个电影推荐系统的核心.系统采用由grouplens项目组从美国著名电影网站movielens整理的ml-latest-small数据集,该数据集包含了671个用户对9000多部电影的10万条评分数据.首先将该数据集包含的全部文件经过筛选重组之后存储到建好的数据库中,并将数据集按一定比例划分为训练集和测试集,对训练集进行算法分析生成Top-N个性化电影推荐列表,然后在测试集上对算法进行评测,至少包括准确率和召回率两种评测指标.

协同过滤算法是推荐领域最出名也是应用最广泛的推荐算法.所以系统拟采用两种协同过滤算法给出两种不同的推荐结果,一种是基于用户的协同过滤算法,另一种是基于物品的协同过滤算法,用户可以根据两种推荐结果更加合理的选择合适的电影.系统采用了改进之后的ItemCF-IUF和UserCF-IIF算法,对计算用户相似度和物品相似度的计算都做出了改进.最后通过计算两种算法的准确率(Precision)、召回率(Recall)和流行度从而对系统进行评测、并比较了两种算法各自的优势和劣势.实验证明,改进后的算法比原始的协同过滤算法推荐效果要好ÿ

基于协同过滤算法实现选课推荐系统

新版本教务管理系统

教务管理系统选课功能

1.系统功能

1、用户账户管理2、学生个人信息的查看与修改3、学生的网上选课与课程的评分4、教师个人信息的查看与修改5、教师对学生课程评价结果的查看6、管理员对学生信息与教师信息的查看与添加7、管理员对课程的增删改查8、管理员对课程评价结果的统计与删除。9、根据学生对课程评分的高低,在学生选课时进行推荐。

2、推荐算法的实现思路欧氏距离相似性度量

在数学中,欧几里得距离或欧几里得度量是欧几里得空间中两点间“普通”(即直线)距离。使用这个距离,欧氏空间成为度量空间。相关联的范数称为欧几里得范数。二维空间的公式

基于用户的协同过滤算法

基于一个这样的假设“跟你喜好相似的人喜欢的东西你也很有可能喜欢。”所以基于用户的协同过滤主要的任务就是找出用户的最近邻居,从而根据最近邻居的喜好做出未知项的评分预测。这种算法主要分为3个步骤:

用户评分可以分为显性评分和隐形评分两种。显性评分就是直接给项目评分(例如用户对电影评分),隐形评分就是通过评价或是购买的行为给项目评分(例如淘宝上购买东西或者评论)。寻找最近邻居这一步就是寻找与你距离最近的用户,测算距离一般采用以下三种算法:余弦定理相似性度量、欧氏距离相似度度量和杰卡德相似性度量。后面的demo会以欧氏距离相似度度量进行说明。推荐产生了最近邻居集合后,就根据这个集合对未知项进行评分预测。把评分最高的N个项推荐给用户。

这种算法存在性能上的瓶颈,当用户数越来越多的时候,寻找最近邻居的复杂度也会大幅度的增长。

参考:https://www.jianshu.com/p/d0df3ead55a1

packagecn.ltysyn.task;importstaticorg.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;importjava.util.ArrayList;importjava.util.Collections;importjava.util.Comparator;importjava.util.HashMap;importjava.util.List;importjava.util.Map;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.scheduling.annotation.Scheduled;importorg.springframework.stereotype.Component;importcn.ltysyn.bean.Course;importcn.ltysyn.bean.Student;importcn.ltysyn.service.ICourseService;importcn.ltysyn.service.IElectiveService;importcn.ltysyn.service.IRecommendService;importcn.ltysyn.service.IStudentService;@ComponentpublicclassMyCFRecomment{//获取学生编号@AutowiredprivateIStudentServicestudentService;//获取课程信息@AutowiredprivateICourseServicecourseService;//获取评分的信息@AutowiredprivateIElectiveServiceelectiveService;@AutowiredprivateIRecommendServiceiRecommendService;////创建用户信息////privateListstuList=newArrayList();//privatestaticint[]stuArr={1,2,3};////创建课程信息//privatestaticint[]couArr={10,20,30};////创建评分的集合(学生id,分数集合)//privatestaticMapgoalMap=newHashMap();@Scheduled(cron="00/10***?")publicvoidrecommend(){//获取到所有的学生ListselectAllStudent=studentService.selectAllStudent();//获取所有的课程//获取评分信息根据学生id和课程id获取评分信息if(selectAllStudent.size()!=0){MapgoalMap=newHashMap();ListstuList=newArrayList();ListselectAllCourse=(List)courseService.selectAllCourse();for(Studentstu:selectAllStudent){ListcourtsGoals=newArrayList();for(Coursecou:selectAllCourse){CourtsGoalcourtsGoal=newCourtsGoal();Integergoal=electiveService.selectByStuAndCourseId(stu.getStuId(),cou.getCourseId());courtsGoal.setCourtsId(cou.getCourseId());courtsGoal.setGoal(goal);courtsGoals.add(courtsGoal);}//获取到学生与课程评分的关系数据goalMap.put(stu.getStuId(),courtsGoals);stuList.add(stu.getStuId());}System.out.println(goalMap);//System.out.println(selectAllCourse);//计算用户相似度MapdataMap=calcUserSimilarity(stuList.toArray(),goalMap);//计算课程的推荐度MaprecommendCourse=calcRecommendCourse(dataMap,goalMap);//处理推荐电影列表MaphandleRecommendCourse=handleRecommendCourse(recommendCourse,goalMap);//删除所有推荐列表信息delectAllRecommendCourse();//保存推荐列表信息saveRecommendCourse(handleRecommendCourse);//删除重复的推荐信息//repeatRecomendCourse();}else{}}privatevoidrepeatRecomendCourse(){//TODOAuto-generatedmethodstubiRecommendService.repeatRecomendCourse();}privatevoiddelectAllRecommendCourse(){//TODOAuto-generatedmethodstubiRecommendService.delectAllRecommendCourse();}privatevoidsaveRecommendCourse(MaphandleRecommendCourse){//TODOAuto-generatedmethodstubiRecommendService.saveRecommendCourse(handleRecommendCourse);}/**publicstaticvoidmain(String[]args){System.out.println(goalMap);*//计算用户相似度MapdataMap=*calcUserSimilarity(stuArr,goalMap);//计算课程的推荐度Map*recommendCourse=calcRecommendCourse(dataMap,goalMap);//处理推荐电影列表*handleRecommendCourse(recommendCourse,goalMap);}*/privatestaticMaphandleRecommendCourse(MaprecommendCourse,MapgoalMap){MaphandleRecommendCourse=newHashMap();for(Map.Entryreco:recommendCourse.entrySet()){//拿到推荐列表Listre_l=reco.getValue();ListhandleCourse=newArrayList();for(Objectobj:re_l){Listlist=goalMap.get(reco.getKey());for(CourtsGoalc_goal:list){if(Integer.parseInt(obj.toString())==c_goal.getCourtsId()){if(c_goal.getGoal()==0){handleCourse.add(c_goal.getCourtsId());}}}}handleRecommendCourse.put(reco.getKey(),handleCourse);}System.out.println("最终推荐列表"+handleRecommendCourse);returnhandleRecommendCourse;}/**计算用户相似度*返回最相近的两个*/publicstaticMapcalcUserSimilarity(Object[]stuArr_p,MapgoalMap_p){//similarityUsers=newArrayList();//遍历学生求出当前学生与其他学生的相似度//相似用户集合MapdataMap=newHashMap();for(Objectstu:stuArr_p){//取两个相似的ListsimilarityUsers=newArrayList();ListuserSimilaritys=newArrayList();//遍历goalMap_pfor(Map.Entrygoal:goalMap_p.entrySet()){//如果当前的学生和存储的key相等则跳过if(stu.toString().equals(goal.getKey().toString())){continue;}ListuserSimilarity=newArrayList();//记录当前的学生编号userSimilarity.add(goal.getKey());userSimilarity.add(calcTwoUserSimilarity(goal.getValue(),goalMap_p.get((Integer)stu)));userSimilaritys.add(userSimilarity);}sortCollection(userSimilaritys);System.out.println("与"+stu+"的相似度为:"+userSimilaritys);similarityUsers.add(userSimilaritys.get(0));similarityUsers.add(userSimilaritys.get(1));dataMap.put((Integer)stu,similarityUsers);}System.out.println(dataMap);//表示该学生与其他两个学生的相似度为多少returndataMap;}/***获取全部推荐课程,计算平均课程推荐度*/privatestaticMapcalcRecommendCourse(MapdataMap,MapgoalMap){Mapcf_map=newHashMap();//存储没有课程的总的推荐分数Mapcf_sumRate=newHashMap();//遍历dataMap分别拿到不同的学生推荐的课程for(Map.Entrydata:dataMap.entrySet()){doublerecommdRate=0,sumRate=0;//拿到的是哪个用户第一个//data.getValue().get(0).get(0);//拿到该用户的相识度值第一个doublexs_1=Double.parseDouble(data.getValue().get(0).get(1).toString());//拿到的是哪个用户第二个//data.getValue().get(1).get(0);//拿到该用户的相识度值第二个doublexs_2=Double.parseDouble(data.getValue().get(1).get(1).toString());Listlist_1=goalMap.get(data.getValue().get(0).get(0));Listlist_2=goalMap.get(data.getValue().get(1).get(0));if(list_1.size()==list_2.size()){ListrecommendCourts=newArrayList();for(inti=0;icf_sumRate.get(cf_d.getKey())/cf_d.getValue().size()){//大于平均推荐度的商品才有可能被推荐targetRecommendCourts.add(obj.get(0));}}target_map.put(cf_d.getKey(),targetRecommendCourts);}System.out.println("最终:"+target_map);returntarget_map;}/***根据用户数据,计算用户相似度(欧氏距离)*@paramuser1Stars其他用户评价分数*@paramuser2Starts当前用户评价的分数*@return*/privatestaticdoublecalcTwoUserSimilarity(Listuser1Stars,Listuser2Starts){floatsum=0;for(inti=0;iDouble.valueOf(o2.get(1).toString())){return1;}elseif(Double.valueOf(o1.get(1).toString())

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。

上一篇

下一篇