資源描述:
《基于MapReduce的Apriori算法代碼及其使用》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
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,//出錯(cuò)的行}publicstaticclassMAPextendsMapper4、xt,Text,IntWritable>{@Overridepublicvoidmap(LongWritablekey,Textvalue,Contextcontext)throwsIOException,InterruptedException{//輸入的一行預(yù)處理文本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_