Mahout algorithm source code analysis: Itembased Collaborative Filtering (3) RowSimilari

Source: Internet
Author: User

Mahout version: 0.7, hadoop version: 1.0.4, jdk: 1.7.0 _ 25 64bit. This article analyzes whether the analysis in the previous article is correct, mainly writing the reading of the output file in the previous article and adding log information to print related variables. First, write the following test file to analyze all the output: [java] package mahout. fansy. item; import java. io. IOException; import java. util. map; import mahout. fansy. utils. read. readArbiKV; import org. apache. hadoop. conf. configuration; import org. apache. hadoop. fs. path; import org. apache. hadoop. io. writable; import org. apache. mahout. math. vector; import org. apache. mahout. math. hadoop. similarity. cooccurrence. vectors; import junit. framework. test Case; public class ReadRowSimilarityJobOut extends TestCase {// test weights output: public void testWeights () throws IOException {String path = "hdfs: // ubuntu: 9000/user/mahout/item/temp/weights/part-r-00000 "; Map <Writable, Writable> map = ReadArbiKV. readFromFile (path); System. out. println ("weights ======================"); System. out. println (map);} // normsPath public void testNormsPath () throws IOException {Str Ing path = "hdfs: // ubuntu: 9000/user/mahout/item/temp/norms. bin "; Vector map = getVector (path); System. out. println ("normsPath ======================"); System. out. println (map);} // maxValues. bin public void testMaxValues () throws IOException {String path = "hdfs: // ubuntu: 9000/user/mahout/item/temp/maxValues. bin "; Vector map = getVector (path); System. out. println ("maxValues ======================"); System. out. println (m Ap);} // numNonZeroEntries. bin public void testNumNonZeroEntries () throws IOException {String path = "hdfs: // ubuntu: 9000/user/mahout/item/temp/numNonZeroEntries. bin "; Vector map = getVector (path); System. out. println ("numNonZeroEntries =================="); System. out. println (map);} // pairwiseSimilarityPath public void testPairwiseSimilarityPath () throws IOException {String path = "hdfs: // ubuntu: 9000/user /Mahout/item/temp/pairwiseSimilarity/part-r-00000 "; Map <Writable, Writable> map = ReadArbiKV. readFromFile (path); System. out. println ("pairwiseSimilarityPath ===================="); System. out. println (map);} // similarityMatrix public void testSimilarityMatrix () throws IOException {String path = "hdfs: // ubuntu: 9000/user/mahout/item/temp/similarityMatrix/part-r-00000 "; Map <Writable, Writable> map = ReadArbiKV. ReadFromFile (path); System. out. println ("similarityMatrix ===================="); System. out. println (map);} // read. binfile public Vector getVector (String path) {Configuration conf = new Configuration (); conf. set ("mapred. job. tracker "," ubuntu: 9001 "); Vector vector = null; try {vector = Vectors. read (new Path (path), conf);} catch (IOException e) {e. printStackTrace () ;}return vector ;}run the above file to get the following output: [plai N] weights ==========================={ 1 = {103:2. 5,102: 3.0. 0}, 2 = {101:2. 0,104: 2.0. 0,102: 2.5}, 3 = {10. 5,107: 5.0. 5,104: 4.0}, 4 = {10. 0,106: 4.0. 5,103: 3.0}, 5 =. 0,105: 3.5. 0,103: 2.0. 0,101: 4.0} normsPath ========================={ 107:25. 0,106: 32.0, 10:32. 5,104: 56.25, 10:44. 25,102: 24.25, 101: 76.25} maxValues ============================{} numNonZeroEntries ====================== {} pairwiseSimila RityPath ==========================={ 102 = {106:0. 14972506706560876,105: 0.14328432723886902. 12789210656028413,103: 0.1975496259559987}, 103 =. 1424339656566283,105: 0.11208890297777215. 14037600977966974}, 101 =. 10275248635596666,106: 0.1424339656566283, 10:0. 1158457425543559,104: 0.16015261286229274. 15548737703860027,102: 0.14201473202245876}, 106 = {}, 107 = {}, 104 =. 13472338607037426, 106:0. 18181818181818182,105: 0.16736577623297264}, 105 =. 2204812092115424,106: 0.14201473202245876 }}similaritymatrix ======================={ 102 = {101:0. 14201473202245876,106: 0.14972506706560876, 10:0. 14328432723886902,104: 0.12789210656028413. 1975496259559987}, 103 = {101:0. 15548737703860027,106: 0.1424339656566283, 10:0. 11208890297777215,104: 0.14037600977966974, 10:0. 1975496259559987}, 101 = {107: 0.10275248635596666. 1424339656566283,105: 0.1158457425543559. 16015261286229274,103: 0.15548737703860027, 10:0. 14201473202245876}, 106 = {101:0. 1424339656566283,105: 0.14201473202245876. 18181818181818182,103: 0.1424339656566283, 10:0. 14972506706560876}, 107 = {105:0. 2204812092115424,104: 0.13472338607037426. 10275248635596666}, 104 =. 13472338607037426,106: 0.18181818181818182, 105: 0.16736577623297264. 14037600977966974,102: 0.12789210656028413. 16015261286229274}, 105 =. 2204812092115424,106: 0.14201473202245876. 16736577623297264,103: 0.11208890297777215, 10:0. 14328432723886902,101: 0.1158457425543559} The first weights is exactly the same as the analysis, so I don't believe it anymore. Then we only analyze pairwiseSimilarityPath and similarityMatrix:

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.