# 透过数据,横看成岭侧成峰

xiaoxiao2021-03-01  16

# 推荐评论

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

# 推荐电影

"用户Lily,kitty,Tom,Tank分别对新增的四部电影做了评分,根据他们的评分为用户Zen推荐一部电影"

Code <!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->SETQUOTED_IDENTIFIEROFFGOSETANSI_NULLSOFFGOALTERPROCEDURE[dbo].[RecommendMoiveForZen](@midint)AS--计算Rxy相似度之和DECLARE@SRxyfloat;select@SRxy=Sum(Rxy)From(selectm1.useriduserA,m2.useriduserB,(sum(m1.level*m2.level)-sum(m1.level)*sum(m2.level)/10)/sqrt((sum(power(m1.level,2))-power(sum(m1.level),2)/10)*(sum(power(m2.level,2))-power(sum(m2.level),2)/10))RxyFrommoive_levelm1,moive_levelm2wherem1.userid<>m2.useridandm1.userid=1andm1.moiveid=m2.moiveidgroupbym1.userid,m2.userid)Temp--select@Srxy--计算对一部新的电影,所有他人评价值的加权平均selectmoive.Name,sum(t.sim)/@Srxy[Level]from(--下面计算的是用户Zen(userid=1)与其他用户的相似度系数,我们使用的是皮尔逊相似度算法selectmoive_level.moiveid,Rxy*moive_level.LevelSimFrom(selectm1.useriduserA,m2.useriduserB,(sum(m1.level*m2.level)-sum(m1.level)*sum(m2.level)/10)/sqrt((sum(power(m1.level,2))-power(sum(m1.level),2)/10)*(sum(power(m2.level,2))-power(sum(m2.level),2)/10))RxyFrommoive_levelm1,moive_levelm2wherem1.userid<>m2.useridandm1.userid=1andm1.moiveid=m2.moiveidgroupbym1.userid,m2.userid)Per,moive_levelwhereper.userB=moive_level.useridandmoive_level.moiveid=@mid)T,moivewhereT.moiveid=moive.idgroupbymoive.nameGOSETQUOTED_IDENTIFIEROFFGOSETANSI_NULLSONGO

Code <!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->DECLARE@RCintDECLARE@midint--SetparametervaluesEXEC@RC=[U-M].[dbo].[RecommendMoiveForZen]469EXEC@RC=[U-M].[dbo].[RecommendMoiveForZen]476EXEC@RC=[U-M].[dbo].[RecommendMoiveForZen]495EXEC@RC=[U-M].[dbo].[RecommendMoiveForZen]574

SET QUOTED_IDENTIFIER OFF GO SET ANSI_NULLS OFF GO ALTER PROCEDURE [ dbo ] . [ EuclideanDistanceForMoive ] @moiveidA int , @moiveidB int AS select * From moive where id = @moiveidA ; select * From moive where id = @moiveidB ; select @moiveidA MoiveA, @moiveidB MoiveB, sqrt ( sum (result))Distance From ( select m1. * , power (m1. level - m2. level , 2 )result From moive_levelm1,moive_levelm2 where m1.moiveid = @moiveidA and m2.moiveid = @moiveidB and m1.userid = m2.userid)T GO SET QUOTED_IDENTIFIER OFF GO 相关资源：p18f4680芯片的电能计量 源代码