本文整理汇总了Java中org.apache.mahout.cf.taste.model.PreferenceArray.setUserID方法的典型用法代码示例。如果您正苦于以下问题:Java PreferenceArray.setUserID方法的具体用法?Java PreferenceArray.setUserID怎么用?Java PreferenceArray.setUserID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.cf.taste.model.PreferenceArray
的用法示例。
在下文中一共展示了PreferenceArray.setUserID方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadInMemory
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入方法依赖的package包/类
public DataModel loadInMemory() {
// In-memory DataModel - GenericDataModels
FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>();
PreferenceArray prefsForUser1 = new GenericUserPreferenceArray(10);
prefsForUser1.setUserID(0, 1L);
prefsForUser1.setItemID(0, 101L);
prefsForUser1.setValue(0, 3.0f);
prefsForUser1.setItemID(1, 102L);
prefsForUser1.setValue(1, 4.5F);
preferences.put(1L, prefsForUser1); // use userID as the key
//TODO: add others users
// Return preferences as new data model
DataModel dataModel = new GenericDataModel(preferences);
return dataModel;
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:22,代码来源:BookRecommender.java
示例2: recommend
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入方法依赖的package包/类
public List<RecommendedItem> recommend(long userId, PreferenceArray preferences) throws TasteException {
if (userExistsInDataModel(userId)) {
return recommender.recommend(userId, noItems);
}
else {
PlusAnonymousConcurrentUserDataModel plusModel = (PlusAnonymousConcurrentUserDataModel) recommender.getDataModel();
// Take an available anonymous user form the poll
Long anonymousUserID = plusModel.takeAvailableUser();
// Set temporary preferences
PreferenceArray tempPrefs = preferences;
tempPrefs.setUserID(0, anonymousUserID);
// tempPrefs.setItemID(0, itemID);
plusModel.setTempPrefs(tempPrefs, anonymousUserID);
List<RecommendedItem> results = recommender.recommend(anonymousUserID, noItems);
// Release the user back to the poll
plusModel.releaseUser(anonymousUserID);
return results;
}
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:27,代码来源:OnlineRecommendation.java
示例3: getGenericDataModel
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入方法依赖的package包/类
private DataModel getGenericDataModel() {
FastByIDMap<PreferenceArray> preferences =
new FastByIDMap<PreferenceArray>();
List<User> users = userService.getAllUsers();
for (int j = 0; j < users.size(); j++) {
List<Preference2d> preference2ds =
preference2dService.getPreferencesByUserId(users.get(j).getId());
PreferenceArray prefsForUser =
new GenericUserPreferenceArray(preference2ds.size());
prefsForUser.setUserID(j, users.get(j).getId());
for (int i = 0; i < preference2ds.size(); i++) {
prefsForUser.setItemID(i, preference2ds.get(i).getRestaurantId());
prefsForUser.setValue(i, preference2ds.get(i).getScore().floatValue());
}
preferences.put(j, prefsForUser);
}
return new GenericDataModel(preferences);
}
示例4: get
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入方法依赖的package包/类
@Override
public PreferenceArray get(Long userID) throws TasteException {
try {
List<Entity> results = getItemsForUser(userID);
if(results == null || results.isEmpty()) {
throw new NoSuchUserException(userID);
}
int i = 0;
PreferenceArray prefs = new GenericUserPreferenceArray(results.size());
prefs.setUserID(0, userID);
for (Entity entity : results) {
prefs.setItemID(
i,
DatastoreHelper.getLong(
DatastoreHelper.getPropertyMap(entity).get(ITEM_ID_COLUMN)
)
);
prefs.setValue(i, 1f);
i++;
}
return prefs;
} catch (DatastoreException e) {
throw new TasteException(e);
}
}