Mahout中基于GenericUserBasedRecommender的候选策略 [英] Candidate Strategy for GenericUserBasedRecommender in Mahout
问题描述
在mahout中,您可以为GenericItemBasedRecommender
定义CandidateItemsStrategy
,以使特定项目(例如,某个类别的排除在外.
使用GenericUserBasedRecommender
时,这是不可能的.如何使用GenericUserBasedRecommender
完成此操作?是使用IDRescorer
做到这一点的唯一方法吗?如果可能的话,我想避免使用IDRescorer
.谢谢您的帮助!
In mahout you can define a CandidateItemsStrategy
for GenericItemBasedRecommender
such that specific items e.g. of a certain category are excluded.
When using a GenericUserBasedRecommender
this is not possible. How can I accomplish this with GenericUserBasedRecommender
? Is the only way to do this using a IDRescorer
? If possible I'd like to avoid using a IDRescorer
. Thank you for your help!
对于基于项目的推荐器,我这样做:
For the item based recommender I do it like this:
private final class OnlySpecificlItemsStrategy implements CandidateItemsStrategy {
private final JpaDataModel dataModel;
public OnlySpecificlItemsStrategy(JpaDataModel dataModel) {
this.dataModel = dataModel;
}
@Override
public FastIDSet getCandidateItems(long userID, PreferenceArray preferencesFromUser, DataModel dataModel) throws TasteException {
List<Long> specificlItemIDs = this.dataModel.getSpecificlItemIDs();
FastIDSet candidateItemIDs = new FastIDSet();
for (long itemID : specificlItemIDs)
candidateItemIDs.add(itemID);
for (int j = 0; j < preferencesFromUser.length(); j++)
candidateItemIDs.remove(preferencesFromUser.getItemID(j));
return candidateItemIDs;
}
}
对于基于用户的推荐器,我使用Rescorer进行:
For the user based recommender I do it with a Rescorer:
public class FilterIDsRescorer implements IDRescorer {
FastIDSet allowedIDs;
public FilterIDsRescorer(FastIDSet allowedIDs) {
this.allowedIDs = allowedIDs;
}
@Override
public double rescore(long id, double originalScore) {
return originalScore;
}
@Override
public boolean isFiltered(long id) {
return !this.allowedIDs.contains(id);
}
}
,然后按如下所示进行设置:
and then set it up like this:
List<Long> specificItemIDsList = dataModel.getOtherSpecificlItemIDs();
FastIDSet specificItemIDs = new FastIDSet(specificItemIDsList.size());
for (Long id : specificItemIDsList) {
specificItemIDs.add(id);
}
this.filterIDsRescorer = new FilterIDsRescorer(specificItemIDs );
userBasedRecommender.recommend(userID, howMany, this.filterIDsRescorer)
出于过滤/排除某些项目的目的,我还可以为每种类型的推荐器子类化我的数据模型,但是后来我无法共享会影响性能的同一数据模型实例.
For the purpose of filtering/excluding certain items I could also subclass my data model for each type of recommender, but then I cannot share the same data model instance which would have an impact on performance.
推荐答案
没有方法可以做到这一点.基于用户和基于项目的算法不是很对称,主要是有目的的.基于用户的系统已经具有用户邻里的概念,类似于这种想法. IDRescorer
不相关.
There isn't a way to do this. The user-based and item-based algorithms are not quite symmetric, and it's mostly on purpose. The user-based system already has a notion of user neighborhood which is kind of like this idea. IDRescorer
is unrelated.
这篇关于Mahout中基于GenericUserBasedRecommender的候选策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!