Mahout 中 GenericUserBasedRecommender 的候选策略

发布于 2024-12-25 18:05:42 字数 2102 浏览 0 评论 0原文

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神经暖 2025-01-01 18:05:42

没有办法做到这一点。基于用户和基于项目的算法并不完全对称,而且主要是故意的。基于用户的系统已经有了用户邻域的概念,有点像这个想法。 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文