【问题标题】:PlusAnonymousConcurrentUserDataModel example in javaJava中的PlusAnonymousConcurrentUserDataModel示例
【发布时间】:2015-03-25 22:55:40
【问题描述】:

我正在尝试编写应该使用该功能的推荐系统代码 PlusAnonymousConcurrentUserDataModel 获取新用户的临时配置文件。

我正在使用 mahout 谁能举个例子?

任何帮助将不胜感激

干杯 金斯利

【问题讨论】:

    标签: java recommendation-engine hybrid mahout-recommender


    【解决方案1】:

    我假设您已经运行了一个模型,所以这里是您需要的代码来让 PlusAnonymousConcurrentUserDataModel 工作。

    // Build your datamodel
    DataModel dataModel = ...
    
    // Build anonymous data model with previous datamodel
    PlusAnonymousConcurrentUserDataModel anonymousDataModel = new PlusAnonymousConcurrentUserDataModel(dataModel, 100); 
    
    // Configure and build your recommender 
    UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
    UserNeighborhood neighborhood = new NearestNUserNeighborhood(25, similarity, model);//
    
    recommender = new CachingRecommender(new GenericUserBasedRecommender(anonymousDataModel, neighborhood, similarity));
    

    现在,如果用户存在,您可以像往常一样检索推荐。否则:

    //Get new user id
    long newUserID = anonymousDataModel.takeAvailableUser();
    
    // fill a Mahout data structure with the user's preferences
    GenericUserPreferenceArray tempPrefs = new GenericUserPreferenceArray(dUserPreferences.size());
    
    
    int i = 0;
    for(Map.Entry<Long, Float> entry : dUserPreferences.entrySet()) {
        Long key = entry.getKey();
        Float value = entry.getValue();
    
        tempPrefs.setUserID(i, newUserID);
        tempPrefs.setItemID(i, key);
        tempPrefs.setValue(i, value);
    
        i++;
    }
    
    // Add the temporaly preferences to model
    anonymousDataModel.setTempPrefs(tempPrefs, newUserID);
    
    // And get recommendations
    List<RecommendedItem> recommendations = recommender.recommend(newUserID, count);
    

    【讨论】:

    • 嗨@LeiNaD_87,非常感谢您的回复。我很感激。您会看到该函数: long newUserID = anonymousDataModel.takeAvailableUser();不返回有效的用户 ID。该方案试图为不在数据库中的用户推荐。假设数据由 UserID、ItemID 和 Ratings 组成。我想从 dataModel 中检索一个临时用户,并使用该用户 ID 为还没有任何数据的新用户推荐。为什么该函数不从提供的 DataModel 中的用户列表中返回用户?比如 long userID = PlusAnonymousUserDataModel.TEMP_USER_ID;
    • @KingsleyGaius,也许我误解了你想要什么。我的代码使用文件/数据库来学习模型。之后,新用户到来。该用户可能在文件/数据库中有一个 ID,但它不在模型喷气机中。在这种情况下,您应该获得一个带有 takeAvailableUser() 的临时用户 ID,它不在模型中。现在,构建数组 tempPrefs,您可以使用当前模型向新用户推荐项目。
    • 我的问题是您需要的吗?您可以将其标记为帮助他人的回应
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-16
    • 2011-08-18
    • 2014-04-28
    • 2023-03-25
    • 2013-08-02
    • 2011-02-13
    • 1970-01-01
    相关资源
    最近更新 更多