xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 4.72MB
    文件類(lèi)型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-10-29
  • 語(yǔ)言: Python
  • 標(biāo)簽: 基于物品??item??python??

資源簡(jiǎn)介

基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)

資源截圖

代碼片段和文件信息

#?-*-?coding=utf-8?-*-
import?math
import?sys
from?texttable?import?Texttable
from?collections?import?defaultdict
#from?Wtemp?import?*
from?operator?import?itemgetter

#讀取文件
def?readFile(fileData):
????data=[]
????rates=[]
????f=open(fileData“r“)
????data=f.readlines()
????f.close()
????for?line?in?data:
????????dataLine=line.split(“\t“)
????????rates.append([int(dataLine[0])int(dataLine[1])int(dataLine[2])])
????return?rates

#創(chuàng)建字典,生成用戶(hù)評(píng)分的數(shù)據(jù)結(jié)構(gòu)
#???輸入:數(shù)據(jù)集合,格式:用戶(hù)id\t硬盤(pán)id\t用戶(hù)評(píng)分
#???輸出:1.用戶(hù)字典:dic[用戶(hù)id]=[(電影id電影評(píng)分)...]
#????????2.電影字典:dic[電影id]=[用戶(hù)id1用戶(hù)id2...]
def?createDict(rates):
????user_dict={}
????movie_dict={}
????for?i?in?rates:
????????if?i[0]?in?user_dict:
????????????user_dict[i[0]].append((i[1]i[2]))
????????else:
????????????user_dict[i[0]]=[(i[1]i[2])]
????????if?i[1]?in?movie_dict:
????????????movie_dict[i[1]].append(i[0])
????????else:
????????????movie_dict[i[1]]=[i[0]]
????return?user_dictmovie_dict


#建立物品倒排表計(jì)算物品相似度
def?itemCF(user_dict):
????N=dict()
????C=defaultdict(defaultdict)
????W=defaultdict(defaultdict)
????for?key?in?user_dict:
????????for?i?in?user_dict[key]:
????????????if?i[0]?not?in?N.keys():?#i[0]表示movie_id
????????????????N[i[0]]=0
????????????N[i[0]]+=1???????????????#N[i[0]]表示評(píng)論過(guò)某電影的用戶(hù)數(shù)
????????????for?j?in?user_dict[key]:
????????????????if?i==j:
????????????????????continue
????????????????if?j?not?in?C[i[0]].keys():
????????????????????C[i[0]][j[0]]=0
????????????????C[i[0]][j[0]]+=1??????#C[i[0]][j[0]]表示電影兩兩之間的相似度,eg:同時(shí)評(píng)論過(guò)電影1和電影2的用戶(hù)數(shù)
????for?irelated_item?in?C.items():
????????for?jcij?in?related_item.items():
????????????W[i][j]=cij/math.sqrt(N[i]*N[j])?
????return?W

#結(jié)合用戶(hù)喜好對(duì)物品排序
def?recommondation(user_iduser_dictK):
????rank=defaultdict(int)
????l=list()
????W=itemCF(user_dict)
????for?iscore?in?user_dict[user_id]:?#i為特定用戶(hù)的電影id,score為其相應(yīng)評(píng)分
????????for?jwj?in?sorted(W[i].items()key=itemgetter(1)reverse=True)[0:K]:?#sorted()的返回值為listlist的元素為元組
????????????if?j?in?user_dict[user_id]:
????????????????continue
????????????rank[j]+=score*wj?#先找出用戶(hù)評(píng)論過(guò)的電影集合,對(duì)每一部電影id,假設(shè)其中一部電影id1找出與該電影最相似的K部電影,計(jì)算出在id1下用戶(hù)對(duì)每部電影的興趣度,接著迭代整個(gè)用戶(hù)評(píng)論過(guò)的電影集合,求加權(quán)和,再排序,可推薦出前n部電影,我這里取10部。
????l=sorted(rank.items()key=itemgetter(1)reverse=True)[0:10]
????return?l
????????????????????????????????

#獲取電影列表
def?getMovieList(item):
????items={}
????f=open(item“r“)
????movie_content=f.readlines()
????f.close()
????for?movie?in?movie_content:
????????movieLine=movie.split(“|“)
????????items[int(movieLine[0])]=movieLine[1:]
????return?items

#主程序
if?__name__==‘__main__‘:
????itemTemp=getMovieList(“E:/SHI/learning/python/ml-100k/u.item“)?#獲取電影列表
????fileTemp=readFile(“E:/SHI/learning/python/ml-100k/u.data“)?????#讀取文件
????user_dicmovie_dic=createDict(fileTemp)????????????????????????#創(chuàng)建字典
????user_id=66
????movieTemp=recommondation(user_iduser_dic80)???????????????#對(duì)電影排序
????rows=[]
????table=Texttable()??????????????????????????????????????

?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????目錄???????????0??2018-09-11?10:47??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\
?????文件????????4018??2017-02-21?13:37??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\itemCFbyMyself.py
?????目錄???????????0??2018-09-11?10:47??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\
?????文件?????????716??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\allbut.pl
?????文件?????????643??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\mku.sh
?????文件????????6750??2016-01-30?04:26??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\README
?????文件?????1979173??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u.data
?????文件?????????202??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u.genre
?????文件??????????36??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u.info
?????文件??????236344??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u.item
?????文件?????????193??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u.occupation
?????文件???????22628??2000-07-20?05:09??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u.user
?????文件?????1586544??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u1.base
?????文件??????392629??2001-03-09?02:32??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u1.test
?????文件?????1583948??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u2.base
?????文件??????395225??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u2.test
?????文件?????1582546??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u3.base
?????文件??????396627??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u3.test
?????文件?????1581878??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u4.base
?????文件??????397295??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u4.test
?????文件?????1581776??2001-03-09?02:34??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u5.base
?????文件??????397397??2001-03-09?02:33??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\u5.test
?????文件?????1792501??2001-03-09?02:34??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\ua.base
?????文件??????186672??2001-03-09?02:34??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\ua.test
?????文件?????1792476??2001-03-09?02:34??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\ub.base
?????文件??????186697??2001-03-09?02:34??基于物品的協(xié)同過(guò)濾算法itemCF原理及python代碼實(shí)現(xiàn)\ml-100k\ub.test

評(píng)論

共有 條評(píng)論