Mahout algorithm Canopy Source analysis: Get input data

Source: Internet
Author: User
Keywords nbsp algorithm Java face
For canopy input data needs to be in the form of sequential files, while ensuring Key:text, http://www.aliyun.com/zixun/aggregation/9541.html "> Value:vectorwritable. Last night prepared to use a simple Java program to get ready to input data, but always will be a problem, last night's problem "can not find the file" for the moment has not found the reason.

In fact, if you just want to get input data, you can use the method provided by Mahout official website to copy the Mahout-distribution-0.7.zip to the virtual machine directly after getting the *.txt file of the sequence, (in/etc/ Profile to configure the next hadoop_home variable) and then locate the Mahout_home/bin directory, perform chmod +x mahout, and then perform the respective

[python] view plaincopy./mahout seqdirectory-i <input>-o <output> [python] view plaincopy./mahout Seq2sparse-i <output>/chunk-0-o <output-in>

The above <input>, <output> corresponds to its own input and output; The data I use is not the full data of the Reuters dataset, but the top three: REUT2-000.SGM, REUT2-001.SGM, REUT2-002.SGM, such data after Extractreuters became 3,000 files, and then after Seqdirectory merged into a 2.41M data file. Seq2sparse has 7 jobs, each job is responsible for its own content, this temporary analysis, the final result in the <output-in>/tfidf-vectors, that is, input data;

With the input data you can run the program, first, regardless of what the program looks like, first run out of the results to say:

[Java]&nbsp;view plaincopy&nbsp;package&nbsp;mahout.test.canopy;&nbsp; import&nbsp;java.io.ioexception;&nbsp; import&nbsp;org.apache.hadoop.conf.configuration;&nbsp; import&nbsp;org.apache.hadoop.fs.path;&nbsp; Import &nbsp;org.apache.mahout.clustering.canopy.CanopyDriver;&nbsp; import&nbsp; org.apache.mahout.common.distance.distancemeasure;&nbsp; import&nbsp; org.apache.mahout.common.distance.euclideandistancemeasure;&nbsp; public&nbsp;class&nbsp;canopytest&nbsp;{ &nbsp; &nbsp; &nbsp; Public&nbsp;static&nbsp;void&nbsp;main (String[]&nbsp;args) &nbsp;throws&nbsp; classnotfoundexception,&nbsp;ioexception,&nbsp;interruptedexception&nbsp;{&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Configuration&nbsp;conf&nbsp;=new&nbsp;configuration ();&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Conf.set (" Mapred.job.tracker ",&nbsp;" 192.168.128.138:9001 ");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Path&nbsp;input=new&nbsp;path ( "Hdfs://hadoop:9000/user/hadoop/output/canopyvec/tfidf-vectors");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Path&nbsp;outPut=new&nbsp;path ("Hdfs://hadoop:9000/user/hadoop/output/canopy-output");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Distancemeasure&nbsp;measure=new&nbsp;euclideandistancemeasure ();&nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; Canopydriver.buildclusters (conf,&nbsp;input,&nbsp;output,&nbsp;measure,&nbsp;33.1,&nbsp;22.1,&nbsp;3,&nbsp; False);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SYSTEM.OUT.PRINTLN ("Job&nbsp;is&nbsp;done."); &nbsp; &nbsp; &nbsp;}&nbsp;}&nbsp;

At the beginning of my T1, T2 set to 3.1, 2.1 results map out of the result is 0 (this is not known what it means), and later changed to see the results of the map output of 509 records, Reduece Output 3 Records (the set value of the parameter Clusterfileter: 3), the final output is: canopy-output/clusters-0-final/part-r-00000.

In order to facilitate the observation of the following, so do not use the above data, and the use of their own data, to create data before the first need to know the format of the input data, then use the following code to see what the input data is:

[Java] view plaincopy package mahout.test.utils;  Import java.io.IOException;  Import org.apache.hadoop.conf.Configuration;  Import Org.apache.hadoop.fs.Path;  Import Org.apache.hadoop.io.Text;  Import Org.apache.hadoop.mapreduce.Job;  Import Org.apache.hadoop.mapreduce.Mapper;  Import Org.apache.hadoop.mapreduce.lib.input.SequenceFileInputFormat;  Import Org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;  Import Org.apache.hadoop.util.ToolRunner; Import Org.apache.mahout.common.AbstractJob;

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.