预览加载中,请您耐心等待几秒...
1/7
2/7
3/7
4/7
5/7
6/7
7/7

在线预览结束,喜欢就下载吧,查找使用更方便

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

C#实现协同过滤算法的实例代码C#实现协同过滤算法的实例代码还在找C#实现协同过滤算法的'代码吗?下面小编为大家整理了C#实现协同过滤算法的实例代码,希望能帮到大家!复制代码代码如下:usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespaceSlopeOne{publicclassRating{publicfloatValue{get;set;}publicintFreq{get;set;}publicfloatAverageValue{get{returnValue/Freq;}}}publicclassRatingDifferenceCollection:Dictionary{privatestringGetKey(intItem1Id,intItem2Id){return(Item1Id<Item2Id)?Item1Id+"/"+Item2Id:Item2Id+"/"+Item1Id;}publicboolContains(intItem1Id,intItem2Id){returnthis.Keys.Contains(GetKey(Item1Id,Item2Id));}publicRatingthis[intItem1Id,intItem2Id]{get{returnthis[this.GetKey(Item1Id,Item2Id)];}set{this[this.GetKey(Item1Id,Item2Id)]=value;}}}publicclassSlopeOne{publicRatingDifferenceCollection_DiffMarix=newRatingDifferenceCollection();//ThedictionarytokeepthediffmatrixpublicHashSet_Items=newHashSet();//TrackinghowmanyitemstotallypublicvoidAddUserRatings(IDictionaryuserRatings){foreach(varitem1inuserRatings){intitem1Id=item1.Key;floatitem1Rating=item1.Value;_Items.Add(item1.Key);foreach(varitem2inuserRatings){if(item2.Key<=item1Id)continue;//Eliminateredundancyintitem2Id=item2.Key;floatitem2Rating=item2.Value;RatingratingDiff;if(_DiffMarix.Contains(item1Id,item2Id)){ratingDiff=_DiffMarix[item1Id,item2Id];}else{ratingDiff=newRating();_DiffMarix[item1Id,item2Id]=ratingDiff;}ratingDiff.Value+=item1Rating-item2Rating;ratingDiff.Freq+=1;}}}//InputratingsofalluserspublicvoidAddUerRatings(IListRatings){foreach(varuserRatingsinRatings){AddUserRatings(userRatings);}}publicIDictionaryPredict(IDictionaryuserRatings){DictionaryPredictions=newDictionary();foreach(varitemIdinthis._Items){if(userRatings.Keys.Contains(itemId))continue;//Userhasratedthisitem,justskipitRatingitemRating=newRating();foreach(varuserRatinginuserRatings){if(userRating.Key==itemId)continue;intinputItemId=userRating.Key;if(_DiffMarix.Contains(itemId,inputItemId)){Ratingdiff=_DiffMarix[itemId,inputItemId];itemRating.Value+=diff.Freq*(userRating.Va