You can try using PlusAnonymousUserDataModel
to recommend items to anonymous users. This can be done by creating wrapper around your recommender class like this:
public class WithAnonymousRecommender extends Recommender {
private final PlusAnonymousUserDataModel plusAnonymousModel;
public WithAnonymousRecommender(DataModel model) throws TasteException, IOException {
super(new PlusAnonymousUserDataModel(model));
plusAnonymousModel = (PlusAnonymousUserDataModel) getDataModel();
}
public synchronized List<RecommendedItem> recommend( PreferenceArray anonymousUserPrefs, int howMany) throws TasteException {
plusAnonymousModel.setTempPrefs(anonymousUserPrefs);
List<RecommendedItem> recommendations = recommend(PlusAnonymousUserDataModel.TEMP_USER_ID, howMany, null);
plusAnonymousModel.clearTempPrefs();
return recommendations;
}
//Test it
public static void main(String[] args) throws Exception {
PreferenceArray anonymousPrefs = new GenericUserPreferenceArray(3);
anonymousPrefs.setUserID(0, PlusAnonymousUserDataModel.TEMP_USER_ID);
anonymousPrefs.setItemID(0, 123L); anonymousPrefs.setValue(0, 1.0f);
anonymousPrefs.setItemID(1, 123L); anonymousPrefs.setValue(1, 3.0f);
anonymousPrefs.setItemID(2, 123L); anonymousPrefs.setValue(2, 2.0f);
WithAnonymousRecommender recommender = new WithAnonymousRecommender();
List<RecommendedItem> recommendations = recommender.recommend(anonymousPrefs, 10);
System.out.println(recommendations);
}
}
You can find more about this in chapter 5.4 in the book Mahout in Action
However, here all anonymous users will be treated as one user. This can be used to recommend items when the user does not have enough watched/liked items. I suggest if you know the IP address of the user to create temporary users for each IP address and collect implicit feedback (clicks, watched movies...) and remove the user after the user exits the site (or have some timeout to remove the user), because using PLusAnonymousUser
will not give you personalization.