这是个抽象概念,在Mahout中,recommender的输入数据是DataModel。DataModel的实现为各种推荐器算法需要的数据提供了有效的使用。例如,一个DataModel可以在输入数据中,提供一个包括所有user IDs的列表,或提供与一个item相关联的所有分值,或者提供一个为一系列item IDs打分的所有用户的列表。我们将会集中研究一些highlights;一个关于DataModel的API的更详细的描述,可以通过在线文档中找到。
3.3.1 GenericDataModel
这个我们先来看一下,最简单的实现(在内存中实现),GenericDataModel。当你想用编程的方法,而不是基于一个现存的外部数据资源。例如一个文件或相关数据库在内存中创建你的数据表现时,这是非常合适的。它只是以这种形式把分值当作输入数据,这个形式就是一个FastByIDMap映射user IDs到有这些用户的数据的PreferenceArrays上。
列表3.2 基于GenericDataModel,定义输入数据
FastByIDMap<PreferenceArray> preferences =
new FastByIDMap<PreferenceArray>();
PreferenceArray prefsForUser1 = new GenericUserPreferenceArray(10); //A
prefsForUser1.setUserID(0, 1L);
prefsForUser1.setItemID(0, 101L); //B
prefsForUser1.setValue(0, 3.0f); //B
prefsForUser1.setItemID(1, 102L);
prefsForUser1.setValue(1, 4.5f);
… (8 more)
preferences.put(1L, prefsForUser1);// C
DataModel model = new GenericDataModel(preferences); //D
A为user 1建立PreferenceArray
B添加第一个preference,在刚刚创建的10中
C把user 1的preference添加到输入数据上
D创建DataModel
一个GenericDataModel使用多少内存?储存的分值的数目占内存占用的绝对优势。通过一些经验揭示,每一preference占用28个字节的Java heap space 。它包括所有的数据和其他次要数据结构--如指数。如果你喜欢你也可以尝试一下;下载一个GenericDataModel,调用 System.gc() ,几次后,比较Runtime.totalMemory()和Runtime.freeMemory()的结构。这是未加工过的,但应该可以给出一个合理的估计,这个估计就是数据占有多少内存。
3.3.2 基于文件的数据
通常我们不会直接地使用GenericDataModel,而是可能使用FileDataModel: FileDataModel从一个文件中读取数据,并可以在内存中储存作为结果的分值数据,从而转化为GenericDataModel。
几乎任何一个合理的文件都将会这么做。我们在第一节里已经看到了一个这样文件的例子,在这节里,我们创造了一个简单的用逗号分割数据的文件,在这个文件里,每一行都包含一个数据:user ID,item ID,分值。使用Tab分割的文件也同样这么做。如果它们的名字各自以“.zip” 或“.gz”为后缀,使用对应的zip和gzip解压。在压缩格式储存这一数据是一个好想法,因为它是巨大的,并且被压缩好的。
3.3.3 Refreshable组件
分享到:
相关推荐
该资源是mahout in action 中的源码,适用于自学,可在github下载:https://github.com/tdunning/MiA
网上流传的Mahout In Action一般为前13章,本文为完整版,比较难得
mahout in action英文正版电子书,书中附带多个基于mahout的推荐系统源码,是一本学习推荐系统,上手推荐系统的圣经!
9 ■ Clustering algorithms in Mahout 145 10 ■ Evaluating and improving clustering quality 184 11 ■ Taking clustering to production 198 12 ■ Real-world applications of clustering 210 Licensed to ...
Mahout in Action 3. Representing data 4. Making recommendations 5. Taking recommenders to production 6. Distributing recommendation computations Part 2 Clustering 7. Introduction to clustering 8. ...
一些支持 Map-Reduce 的集群实现包括 k-Means、模糊 k-Means、Canopy、Dirichlet 和 Mean-Shift。 Distributed Naive Bayes 和 Complementary Naive Bayes 分类实现。
mahout is a library for data mining / machine learning using Hadoop technologies.
Mahout In Action 2012.pdf 配套源代码 Mahout In Action 2012 Source Code 原书 Mahout In Action 2012 版本 源代码。 帮助理解推荐系统的常用算法,分布式信息挖掘技术。
mahout in action中的example codes进行maven编译时由于maven相关jar包的URL的重定位,故无法进行有效编译,需要下载相关jar包进行手动加载!
Mahout In Action 清晰完整版 聚类分析、算法推荐
mahout in action 第一章 第二章 第三章第四章 第六章第七章 第九章
Mahout in action 实战中文版 高清 完整,,最经典的hadoop机器学习库
Mahout in Action 2012年新版
Mahout in action 中文版,简介,快速入门
mahout in action 目前最全的版本
很不容易找到的Mahout in Action 完整版,而且是2012版的
Mahout in Action is a hands-on introduction to machine learning with Apache Mahout. Following real-world examples, the book presents practical use cases and then illustrates how Mahout can be applied ...