欢迎来到天天文库
浏览记录
ID:38783500
大小:14.04 KB
页数:6页
时间:2019-06-19
《基于MapReduce的Apriori算法代码及其使用》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、packagecom;importjava.io.IOException;importjava.text.DateFormat;importjava.text.SimpleDateFormat;importjava.util.Date;importjava.util.StringTokenizer;importorg.apache.hadoop.conf.Configuration;importorg.apache.hadoop.conf.Configured;importorg.apache.hadoop.fs.FileSystem;importorg.apach
2、e.hadoop.fs.Path;importorg.apache.hadoop.util.Tool;importorg.apache.hadoop.util.ToolRunner;importorg.apache.hadoop.io.IntWritable;importorg.apache.hadoop.io.LongWritable;importorg.apache.hadoop.io.Text;importorg.apache.hadoop.mapreduce.Job;importorg.apache.hadoop.mapreduce.Mapper;impor
3、torg.apache.hadoop.mapreduce.Reducer;importorg.apache.hadoop.mapreduce.lib.input.FileInputFormat;importorg.apache.hadoop.mapreduce.lib.output.FileOutputFormat;publicclassAprioriextendsConfiguredimplementsTool{enumCounter{LINESKIP,//出错的行}publicstaticclassMAPextendsMapper4、xt,Text,IntWritable>{@Overridepublicvoidmap(LongWritablekey,Textvalue,Contextcontext)throwsIOException,InterruptedException{//输入的一行预处理文本StringTokenizeritr=newStringTokenizer(value.toString());String[]values=newString[2];inti=0;while(itr.hasMoreTokens()){values[i]=itr.nextToken();i++;}i5、f(values[0].length()>0&&values[1].length()>0){Stringdd[]=values[1].split(",");System.out.println(values[1]+","+dd.length);int[]result;Stringoutput="";for(intj=1;j6、tem.out.print(result+"");//output+=dd[result]+",";//System.out.print(d[i]+"");output+=dd[result[i]]+",";}//System.out.println();context.write(newText(output.substring(0,output.length()-1)),newIntWritable(1));result=null;output="";}}}}}publicstaticclassREDUCEextendsReducer7、ble,Text,IntWritable>{@Overridepublicvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedException{intCNT=0;for(IntWritablevalue:values){CNT+=value.get();}//intmin_sup=//Interge.context.getConfiguration().get("min_sup");intmin_sup=2;if(CNT>=min_
4、xt,Text,IntWritable>{@Overridepublicvoidmap(LongWritablekey,Textvalue,Contextcontext)throwsIOException,InterruptedException{//输入的一行预处理文本StringTokenizeritr=newStringTokenizer(value.toString());String[]values=newString[2];inti=0;while(itr.hasMoreTokens()){values[i]=itr.nextToken();i++;}i
5、f(values[0].length()>0&&values[1].length()>0){Stringdd[]=values[1].split(",");System.out.println(values[1]+","+dd.length);int[]result;Stringoutput="";for(intj=1;j
6、tem.out.print(result+"");//output+=dd[result]+",";//System.out.print(d[i]+"");output+=dd[result[i]]+",";}//System.out.println();context.write(newText(output.substring(0,output.length()-1)),newIntWritable(1));result=null;output="";}}}}}publicstaticclassREDUCEextendsReducer7、ble,Text,IntWritable>{@Overridepublicvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedException{intCNT=0;for(IntWritablevalue:values){CNT+=value.get();}//intmin_sup=//Interge.context.getConfiguration().get("min_sup");intmin_sup=2;if(CNT>=min_
7、ble,Text,IntWritable>{@Overridepublicvoidreduce(Textkey,Iterablevalues,Contextcontext)throwsIOException,InterruptedException{intCNT=0;for(IntWritablevalue:values){CNT+=value.get();}//intmin_sup=//Interge.context.getConfiguration().get("min_sup");intmin_sup=2;if(CNT>=min_
此文档下载收益归作者所有