0

i am trying to write a recommender systems code that should use the function PlusAnonymousConcurrentUserDataModel to get a temporary profile for a new user.

l am using mahout Can anyone show an example?

Any help will be appreciated

Cheers kingsley

1 Answers1

0

I assumed you already have a model running, so here is the code you need around that to get PlusAnonymousConcurrentUserDataModel working.

// 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));

now, if the user exists, you can retrieve recommendations like always. Otherwise:

//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);
Daniel Argüelles
  • 2,229
  • 1
  • 33
  • 56
  • Hi @LeiNaD_87, Thanks a lot for replying. i appreciate. you see that function: long newUserID = anonymousDataModel.takeAvailableUser(); does not return a valid UserID. The scenario is trying to recommend for a user who is not in the database. So say the data consist of UserID, ItemID and Ratings. i want to retrieve a temporary User from the dataModel and use that userID to recommend for the new user who does not have any data yet. Why does the function not return a user from the list of users in the DataModel provided? like long userID = PlusAnonymousUserDataModel.TEMP_USER_ID; – Kingsley Gaius Apr 29 '15 at 23:40
  • @KingsleyGaius, maybe I missunderstand what you want. My code uses the file/database to learn the model. After that, a new user arrives. That user may have a id in the file/database but it isn't in the model jet. In this case, you should get a temporaly userid with [takeAvailableUser()](http://archive.cloudera.com/cdh4/cdh/4/mahout/mahout-core/org/apache/mahout/cf/taste/impl/model/PlusAnonymousConcurrentUserDataModel.html#takeAvailableUser()) which is NOT in the model. Now, building the array tempPrefs, you can recommend items to the new user using the current model. – Daniel Argüelles Apr 30 '15 at 11:05
  • Is my question what you needed? You can mark it as a response to help others – Daniel Argüelles Jul 02 '15 at 14:17