mahout基本结构
package: org.apache.mahout.cf.taste
- common: 公共类包括,异常,数据刷新接口,权重常量
- eval: 定义构造器接口,类似于工厂模式
- model: 定义数据模型接口
- neighborhood: 定义近邻算法的接口
- recommender: 定义推荐算法的接口
- similarity: 定义相似度算法的接口
- transforms: 定义数据转换的接口
- hadoop: 基于hadoop的分步式算法的实现类
- impl: 单机内存算法实现类
common
Refreshable接口:
public interface Refreshable {
void refresh(Collection<Refreshable> alreadyRefreshed);
}
数据模型
相似度算法
- 基于用户的相似度
public interface UserSimilarity extends Refreshable {
double userSimilarity(long userID1, long userID2) throws TasteException;
void setPreferenceInferrer(PreferenceInferrer inferrer);
}
- 基于物品的相似度
public interface ItemSimilarity extends Refreshable {
double itemSimilarity(long itemID1, long itemID2) throws TasteException;
double[] itemSimilarities(long itemID1, long[] itemID2s) throws TasteException;
long[] allSimilarItemIDs(long itemID) throws TasteException;
}
近邻算法
public interface UserNeighborhood extends Refreshable {
long[] getUserNeighborhood(long userID) throws TasteException;
}
推荐算法
public interface Recommender extends Refreshable {
List<RecommendedItem> recommend(long userID, int howMany) throws TasteException;
List<RecommendedItem> recommend(long userID, int howMany, boolean includeKnownItems) throws TasteException;
List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer) throws TasteException;
List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer, boolean includeKnownItems) throws TasteException;
float estimatePreference(long userID, long itemID) throws TasteException;
void removePreference(long userID, long itemID) throws TasteException;
DataModel getDataModel();
}