Mahout 是 Apache Software Foundation旗下的一個(gè)開(kāi)源項(xiàng)目,提供一些可擴(kuò)展的機(jī)器學(xué)習(xí)領(lǐng)域經(jīng)典算法的實(shí)現(xiàn),旨在幫助開(kāi)發(fā)人員更加方便快捷地創(chuàng)建智能應(yīng)用程序。Mahout包含許多實(shí)現(xiàn),包括聚類(lèi)、分類(lèi)、推薦過(guò)濾、頻繁子項(xiàng)挖掘。此外,通過(guò)使用 Apache Hadoop 庫(kù),Mahout 可以有效地?cái)U(kuò)展到云中。
主要特性
Apache Mahout 運(yùn)行環(huán)境包括
針對(duì)分布式的優(yōu)化
支持Scala API
支持線性代數(shù)操作
支持Scalak擴(kuò)展
支持IScala REPL的交互式shell
集成MLLib庫(kù)
可以運(yùn)行在 Spark、H2O和Flink上
支持稀疏矩陣和向量的加速計(jì)算
和Apache Zeppelin整合轉(zhuǎn)換矩陣tsv
Apache Mahout Samsara 算法包括
隨機(jī)矩陣的奇異值分解算法ssvd、dssvd
隨機(jī)主成分分析算法(spca、dspca)
分布式Cholesky QR(thinQR)
分布式正則化交替最小二乘法(dals)
協(xié)同過(guò)濾算法::Item和Row的相似性
樸素貝葉斯分類(lèi)算法
核心分布算法
我們可以使用Maven很方便地使用它:
從官網(wǎng)下載Maven,解壓到本地,并配置環(huán)境變量,過(guò)程省略。
2. 在eclipse中配置maven

3. 新建一個(gè)Maven Project

4.修改項(xiàng)目的pom.xml,默認(rèn)已經(jīng)有junit依賴(lài)了,我們只需要添加:
XHTML
<dependency>
<groupId>org.apache.mahout</groupId>
<artifactId>mahout-core</artifactId>
<version>0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.12</version>
</dependency>
保存后,選擇Run As->Maven Clean,大約7s后,相關(guān)包下載完成。

5.新建一個(gè)UserCF類(lèi)測(cè)試基于用戶(hù)的協(xié)同過(guò)濾算法:
Java
public class UserCF {
final static int NEIGHBORHOOD_NUM = 2;
final static int RECOMMENDER_NUM = 3;
public static void main(String[] args) throws IOException, TasteException {
String path = UserCF.class.getClassLoader().getResource("").getPath();
String file = "/data/item.csv";
DataModel model = new FileDataModel(new File(path+file));
UserSimilarity user = new EuclideanDistanceSimilarity(model);
NearestNUserNeighborhood neighbor = new NearestNUserNeighborhood(NEIGHBORHOOD_NUM, user, model);
Recommender r = new GenericUserBasedRecommender(model, neighbor, user);
LongPrimitiveIterator iter = model.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = r.recommend(uid, RECOMMENDER_NUM);
System.out.printf("uid:%s", uid);
for (RecommendedItem ritem : list) {
System.out.printf("(%s,%f)", ritem.getItemID(), ritem.getValue());
}
System.out.println();
}
}
}
數(shù)據(jù)為: item.csv
1,101,5.0
1,102,3.0
1,103,2.5
2,101,2.0
2,102,2.5
2,103,5.0
2,104,2.0
3,101,2.5
3,104,4.0
3,105,4.5
3,107,5.0
4,101,5.0
4,103,3.0
4,104,4.5
4,106,4.0
5,101,4.0
5,102,3.0
5,103,2.0
5,104,4.0
5,105,3.5
5,106,4.0
6.運(yùn)行輸出為:

總結(jié):maven在研究開(kāi)源項(xiàng)目的時(shí)候的確很方便,同時(shí)要研究推薦算法,還必須對(duì)mahout源碼進(jìn)一步研究。
參考文檔:http://mahout.apache.org/developers/developer-resources.html
官方網(wǎng)站:http://mahout.apache.org/
開(kāi)源地址:https://github.com/apache/mahout