博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mahout0.7 示例运行纪实
阅读量:7104 次
发布时间:2019-06-28

本文共 2697 字,大约阅读时间需要 8 分钟。

运行太不容易了 所以要记下来以免后面忘记了

首先是数据

vim testdata.txt

第一列为UserID ,第二列为ItemID,第三列为Preference Value 即评分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1
,
101
,
5
1
,
102
,
3
1
,
103
,
2.5
2
,
101
,
2
2
,
102
,
2.5
2
,
103
,
5
2
,
104
,
2
3
,
101
,
2.5
3
,
104
,
4
3
,
105
,
4.5
3
,
107
,
5
4
,
101
,
5
4
,
103
,
3
4
,
104
,
4.5
4
,
106
,
4
5
,
101
,
4
5
,
102
,
3
5
,
103
,
2
5
,
104
,
4
5
,
105
,
3.5
5
,
106
,
4

新建立一个工程

导入 mahout包 mahout-core-0.7-job.jar

这样进行开发的时候就不会出现各种红叉叉  从编程心情上会更好一点

新建一个类 RecommenderIntro

代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import 
org.apache.mahout.cf.taste.impl.model.file.*;
import 
org.apache.mahout.cf.taste.impl.neighborhood.*;
import 
org.apache.mahout.cf.taste.impl.recommender.*;
import 
org.apache.mahout.cf.taste.impl.similarity.*;
import 
org.apache.mahout.cf.taste.model.*;
import 
org.apache.mahout.cf.taste.neighborhood.*;
import 
org.apache.mahout.cf.taste.recommender.*;
import 
org.apache.mahout.cf.taste.similarity.*;
import 
java.io.*;
import 
java.util.*;
public 
class 
RecommenderIntro {
    
private 
RecommenderIntro(){}
                                                                                                                                                                         
    
public 
static 
void 
main(String[] args) 
throws 
Exception {                 
        
DataModel model = 
new 
FileDataModel(
new 
File(
                
"intro.csv"
)); 
// step:1 构建模型
        
UserSimilarity similarity = 
new 
PearsonCorrelationSimilarity(model); 
// 2 计算相似度
        
UserNeighborhood neighborhood = 
new 
NearestNUserNeighborhood(
2
,
                
similarity, model); 
// 3 查找邻近
        
Recommender recommender = 
new 
GenericUserBasedRecommender(model,
                
neighborhood, similarity); 
// 4 构造推荐引擎
        
List<RecommendedItem> recommendations = recommender.recommend(
1
2
);
// 为用户1推荐两个ItemID
        
for 
(RecommendedItem recommendation : recommendations) {
            
System.out.println(recommendation);
        
}
    
}
}

这样就能够运行了

但是会报错 原因在于没有导入它所需要的所有包

在mahout当中 只要你正确安装了都会有他所需要的包

除了google的一个需要自己下

1
2
3
4
5
6
7
mahout-core-
0.7
-job.jar
slf4j-api-
1.6
.
1
.jar
slf4j-jcl-
1.6
.
1
.jar
google-collection-
1.0
-rc2.jar 
//这个找不到 然后需要自己下载一个 guava-r09.zip 用当中的 guava-r09.jar来解决这个google依赖问题
commons-logging-
1.1
.
1
.jar
mahout-math-
0.7
.jar
uncommons-maths-
1.2
.
2
.jar

然后就能够运行了

结果 应该是

1
2
3
4
5
6
7
8
9
10
2013
-
5
-
21 
2
:
45
:
56 
org.slf4j.impl.JCLLoggerAdapter info
信息: Creating FileDataModel 
for 
file /root/input/testMahout.txt
2013
-
5
-
21 
2
:
45
:
56 
org.slf4j.impl.JCLLoggerAdapter info
信息: Reading file info...
2013
-
5
-
21 
2
:
45
:
56 
org.slf4j.impl.JCLLoggerAdapter info
信息: Read lines: 
21
2013
-
5
-
21 
2
:
45
:
56 
org.slf4j.impl.JCLLoggerAdapter info
信息: Processed 
5 
users
RecommendedItem[item:
104
, value:
4.257081
]
RecommendedItem[item:
106
, value:
4.0
]

031454774.png

总结:

主要是依赖问题解决用了比较长的时间

我用的ubuntu 下开发 所以在找包的时候 直接用 find | grep *** 在mahout 的安装目录下去寻找包

参考自:

本文转自    拖鞋崽      51CTO博客,原文链接:http://blog.51cto.com/1992mrwang/1205282

转载地址:http://nsuhl.baihongyu.com/

你可能感兴趣的文章
我的友情链接
查看>>
springboot集成swagger2构建RESTful API文档
查看>>
日志分析(六)压测数据
查看>>
删除该目录下所有文件和子文件夹,但该根文件夹会保留
查看>>
织梦如何与discuz论坛整合一起应用
查看>>
Linux脚本实现远程自动备份
查看>>
SELECT ... INTO OUTFILE中面临的secure_file_priv问题
查看>>
JS常用正则表达式备忘录
查看>>
Phoenix三贴之二:Phoenix二级索引系统
查看>>
java中servletContextListener、httpSessionListener和servletRequestListener三者概述
查看>>
非本专业就当不了数据分析师?
查看>>
接口 (interface)
查看>>
solr搜索
查看>>
AngularDart Material Design 选择
查看>>
我的C盘空间满了,该怎么清理?
查看>>
ApplicationContext的事件机制
查看>>
Nginx安装、默认虚拟主机、用户认证、nginx中PHP解析
查看>>
20.5 shell脚本中的逻辑判断
查看>>
go 包依赖静态分析
查看>>
媒体转码截图和工作流场景常见问题【系列一】
查看>>