posts - 495,comments - 227,trackbacks - 0
          http://www.linuxidc.com/Linux/2012-07/65008.htm


          推薦器實現(xiàn)類在:

          org.apache.mahout.cf.taste.Hadoop.item.RecommenderJob。其輸入數(shù)據(jù)放在默認輸入目錄下,使用mapred.input.dir參數(shù)指定的輸入數(shù)據(jù),是userID,itemID[,preferencevalue]值對形成的文本文件。可以有多個文件存放在該目錄下。

          運行時相關(guān)參數(shù)如下:

          numRecommendations:為每個用戶產(chǎn)生的推薦個數(shù) "Number of recommendations per user"

          usersFile:包含待推薦用戶的用戶ID列表;

          itemsFile:包含待推薦項目的項目ID列表;

          filterFile:用來做推薦過濾的訓練文件,內(nèi)容為使用逗號分隔的userID,itemID對,

          booleanData:不帶推薦值的訓練數(shù)據(jù)文件;

          maxPrefsPerUser:Maximum number of preferences considered per user in final recommendation phase;

          minPrefsPerUser:ignore users with less preferences than this in the similarity computation ;   maxSimilaritiesPerItem:Maximum number of similarities considered per item;

          maxurrencesPerItem:try to cap the number of urrences per item to this;

          similarityClassname:Name of distributed similarity class to instantiate, alternatively use one of the predefined similarities,可用的相似度類有:

           SIMILARITY_URRENCE(DistributedurrenceVectorSimilarity.class),

           SIMILARITY_EUCLIDEAN_DISTANCE(DistributedEuclideanDistanceVectorSimilarity.class),

           SIMILARITY_LOGLIKELIHOOD(DistributedLoglikelihoodVectorSimilarity.class),

           SIMILARITY_PEARSON_CORRELATION(DistributedPearsonCorrelationVectorSimilarity.class),

           SIMILARITY_TANIMOTO_COEFFICIENT(DistributedTanimotoCoefficientVectorSimilarity.class),

           SIMILARITY_UNCENTERED_COSINE(DistributedUncenteredCosineVectorSimilarity.class),

           SIMILARITY_UNCENTERED_ZERO_ASSUMING_COSINE(DistributedUncenteredZeroAssumingCosineVectorSimilarity.class),

           SIMILARITY_CITY_BLOCK(DistributedCityBlockVectorSimilarity.class);

          RecommendJob運行一系列MR任務(wù),在開發(fā)時,可以根據(jù)自己的需要進行改寫。但是RecommendJob申明成final,這個比較頭疼。

          1.itemIDIndex 任務(wù):

          map:解析輸入的itemsFile;將長整型的ID通過算法映射到整形的序號上,以便后續(xù)處理。由于處理中涉及到矩陣計算,每一個項目對應矩陣中的一個維度,所以必須處理成整形;產(chǎn)生序號-ID值對;

          reducer:對序號-ID對進行驗證,產(chǎn)生序號-ID值對;

          2.toUserVector任務(wù):

          ToItemPrefsMapper:從filterFile中讀取偏好信息,轉(zhuǎn)成用戶-偏好值對。

          ToUserVectorReducer:將用戶-偏好*,轉(zhuǎn)成用戶-偏好矢量對,矢量表即為所有的ItemID。

          3.countUsers 任務(wù):計算用戶數(shù)量,輸出為用戶數(shù)量--空。

          4.maybePruneAndTransponse,一個名稱很奇怪的任務(wù)。

          MaybePruneRowsMapper:輸入為任務(wù)2的輸出,生成針對每個item項目的推薦值矩陣單元,即Item序號和矩陣單元的值對。

          ToItemVectorsReducer:輸出為矩陣行號(即Item序號)-矩陣行矢量

          5. RowSimilarityJob: 計算相似度矩陣:這是引用一個現(xiàn)有的任務(wù)來完成計算,輸入為任務(wù)4輸出的矩陣;輸出為相似度矩陣,即item-相似度矢量。其中相似度矢量是當前item和其他item的相似度值形成的矢量。

          6. prePartialMultiply1:輸入為任務(wù)5的輸出,將相似度矩陣中的對角線行,即(N,N)數(shù)值設(shè)置為Double.NaN,為后續(xù)計算做準備;

          7. prePartialMultiply2:輸入為任務(wù)2的輸出,將user-(項目矢量),拆分成item-(userId, 推薦值)對。如果設(shè)置了usersFile,則僅處理usersFile中指定的用戶。

          8. partialMultiply: 合并任務(wù)6和7的額輸出,變成item-(相似度矢量、userId、推薦值) 對。

          9. itemFiltering:如果有filterFile,則處理filterFile文件,轉(zhuǎn)換成item-(相似度矢量、userId、推薦值)對。其中相似度矢量的值為0;

          aggregateAndRecommend:將8和9的輸出合并作為輸入,

          PartialMultiplyMapper: 將item-(相似度矢量、userId、推薦值)集轉(zhuǎn)換成userId-(推薦值,相似度矢量)值對;

          AggregateAndRecommendReducer:匯總map輸出,產(chǎn)生userId-((itemId, 推薦值)列表)值對,其中(itemId, 推薦值)列表是按照推薦度來排序,如果maxPrefsPerUser、minPrefsPerUser、maxurrencesPerItem,則只產(chǎn) 生符合條件的userId值對。

          posted on 2014-12-04 14:39 SIMONE 閱讀(683) 評論(0)  編輯  收藏 所屬分類: hadoop mahout

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 麻阳| 利川市| 花莲县| 亳州市| 永修县| 桓仁| 许昌市| 米脂县| 唐河县| 垫江县| 文安县| 义乌市| 建始县| 龙川县| 衡山县| 西平县| 商南县| 射洪县| 腾冲县| 新化县| 合肥市| 鄂伦春自治旗| 东乡族自治县| 华蓥市| 漳浦县| 清原| 蓝田县| 贺州市| 邹城市| 东山县| 民勤县| 开阳县| 高邑县| 巧家县| 四平市| 沙洋县| 察雅县| 台南市| 内乡县| 隆昌县| 博罗县|