Feedback code for items

Source: Internet
Author: User

#CODING=GBK" "Select User feedback items will score >3 defined as like" "ImportPandas as PDImportNumPy as NPImportCopy#get the degree of differentiationdefGetdiff (Userrates,movie): like=dict () Dislike=dict () Unknown=dict () Likearray=[] Dislikearray=[] Unknownarray=[]     forUser,ratingsinchUserrates.items ():ifMovie not inchRatings:unknown[user]=Ratings forMv,ratinginchRatings.items (): Unknownarray.append (rating)elifRatings[movie]>3: Like[user]=Ratings forMv,ratinginchRatings.items ():ifmv!=Movie:likeArray.append (rating)Else: Dislike[user]=Ratings forMv,ratinginchRatings.items ():ifmv!=Movie:dislikeArray.append (rating) diff=0ifLen (likearray)! =0:diff+=Np.var (Likearray)ifLen (dislikearray)! =0:diff+=Np.var (Dislikearray)ifLen (unknownarray)! =0:diff+=Np.var (Unknownarray)return(Diff,like,dislike,unknown)defSelect (MVS,USERRATES,NODE,EXCEPTMVS,LV): like=dict () Dislike=dict () Unknown=dict () MaxDiff=-100BESTMV=-1000 forMvinchMVS:ifMvinchExceptmvs:ContinueDIFF,TMPA,TMPB,TMPC=Getdiff (USERRATES,MV)ifDiff>MAXDIFF:BESTMV=MV MaxDiff=diff like=Tmpa dislike=TMPB Unknown=tmpc exceptmvs.append (BESTMV) node['movie']=BESTMVPrintLVPrintnode['Tag']    if(lv+1) <=3: node[' like']={'Tag':' like'} node['dislike']={'Tag':'dislike'} node['Unknown']={'Tag':'Unknown'} select (mvs,like,node[' like'],copy.deepcopy (EXCEPTMVS), lv+1) Select (mvs,dislike,node['dislike'],copy.deepcopy (EXCEPTMVS), lv+1) Select (mvs,unknown,node['Unknown'],copy.deepcopy (EXCEPTMVS), lv+1) Data=pd.read_csv ('Data/ratings.dat', sep='::', nrows=80000,header=None) Data=data.ix[:,0:2]groups=Data.groupby ([0])#organize data with rates[User [item]= scoring formrates=dict () forUser,groupinchGroups:rates[user]={a:b forA, binchGroup[[1,2]].itertuples (index=False)}#get a list of itemsMovies = Set ([j forI,j,kinchData.itertuples (index=False)]) Root={'Tag':'Root'}select (movies,rates,root,[],1)PrintRoot

Feedback code for items

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.