欢迎来到天天文库
浏览记录
ID:41631192
大小:61.78 KB
页数:13页
时间:2019-08-29
《基于MapReduce的基于用户的协同过滤算法代码及其使用》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、UserCF类代码:packagecom;importorg.apache.hadoop.conf.Configuration;importorg-apache.hadoop.util.ToolRunner;publicclassUserCF{publicstaticvoidmain(String[]args)throwsException{TooIRunner.run(newConfiguration(),newUserCFlf),args);TooIRunner.run(newConfiguration(),newUserCF2(),args);TooIRunner.ru
2、n(newConfiguration(),newUserCF3(),args);TooIRunner.run(newConfiguration(),newUserCF4(),args);TooIRunner.run(newConfiguration(),newUserCFSO,args);ToolRunner.run(newConfiguration(),newUserCF6(),args);}}UserCFl类代码:packagecom;importjava.io」OException;importjava.util.ArrayList;importjava.util.Li
3、st;importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.conf.Configured;importorg.apache.hadoop.fs.FileSystem;importorg.apache.hadoop.fs.Path;importorg.apache.hadoop.io.LongWritable;importorg.apache.hadoop.io.Text;importorg.apache.hadoop.mapreduceJob;importorg.apache.hadoop.ma
4、preduce.Mapper;importorg.apache.hadoop.mapreduce.Reducer;importorg.apache.hadoop.mapreduce」ib・input.FilelnputFormat;importorg.apache.hadoop.mapreduce」ib・input.TextlnputFormat;importorg.apache.hadoop.mapreduce」ib.output・FileOutputFormat;importorg.apache.hadoop.mapreduce.lib.output.TextOutput
5、Format;importorg.apache.hadoop.util.Tool;publicclassUserCFlextendsConfiguredimplementsTool{publicstaticclassMapperlextendsMapper{publicvoidmap(LongWritablekey,Textvalue,Contextcontext)throwslOException,InterruptedException{String[]values=value.toString().split("
6、t");context.write(newText(values[l]),newText(values[0]+"tH+values[2]));}}publicstaticclassReducerlextendsReducer{publicvoidreduce(Textkey,lterablevalues,Contextcontext)throwslOException,InterruptedException{Listtmp」ist=newArrayList7、values){tmp_list.add(tmp.toString());}for(inti=O;i
7、values){tmp_list.add(tmp.toString());}for(inti=O;i
此文档下载收益归作者所有