Mahout 中 GenericUserBasedRecommender 的候选策略
在 mahout 中,您可以为 GenericItemBasedRecommender
定义 CandidateItemsStrategy
,以便排除特定项目(例如某个类别的项目)。 当使用GenericUserBasedRecommender
时,这是不可能的。如何使用 GenericUserBasedRecommender
实现此目的?使用 IDRescorer
是执行此操作的唯一方法吗?如果可能的话,我想避免使用 IDRescorer
。感谢您的帮助!
[编辑]
对于基于项目的推荐器,我这样做:
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 进行操作:
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);
}
}
然后像这样设置它:
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)
为了过滤/排除某些项目,我还可以对我的数据模型进行子类化对于每种类型的推荐器,但我无法共享相同的数据模型实例,这会对性能产生影响。
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!
[Edit]
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;
}
}
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有办法做到这一点。基于用户和基于项目的算法并不完全对称,而且主要是故意的。基于用户的系统已经有了用户邻域的概念,有点像这个想法。
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.