本文整理汇总了Java中org.apache.mahout.cf.taste.model.PreferenceArray类的典型用法代码示例。如果您正苦于以下问题:Java PreferenceArray类的具体用法?Java PreferenceArray怎么用?Java PreferenceArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PreferenceArray类属于org.apache.mahout.cf.taste.model包,在下文中一共展示了PreferenceArray类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: IRState
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
public void IRState(String taskName) {
String itemmodelsPath = RecommendConfig.class.getResource("/").getPath() + "itemmodels.csv";
HadoopUtil.download(taskName, itemmodelsPath, false);
try {
DataModel fileDataModel = new FileDataModel(new File(itemmodelsPath));
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics irStatistics = irStatsEvaluator.evaluate(new RecommenderBuilder() {
@Override
public org.apache.mahout.cf.taste.recommender.Recommender buildRecommender(final DataModel dataModel) throws TasteException {
UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(dataModel);
UserNeighborhood userNeighborhood = new NearestNUserNeighborhood(5, userSimilarity, dataModel);
return new GenericUserBasedRecommender(dataModel, userNeighborhood, userSimilarity);
}
}, new DataModelBuilder() {
@Override
public DataModel buildDataModel(final FastByIDMap<PreferenceArray> fastByIDMap) {
return new GenericDataModel(fastByIDMap);
}
}, fileDataModel, null, 5, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
System.out.println("查准率:" + irStatistics.getPrecision());
System.out.println("查全率:" + irStatistics.getRecall());
} catch (TasteException | IOException e) {
e.printStackTrace();
}
}
开发者ID:babymm,项目名称:mmsns,代码行数:26,代码来源:MahoutRecommender.java
示例2: testBuildKNNRecommender
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Test
public void testBuildKNNRecommender() {
GenericRecommenderBuilder rb = new GenericRecommenderBuilder();
FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));
DataModel dm = new GenericDataModel(userData);
Recommender rec = null;
String recommenderType = "org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender";
String similarityType = "org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity";
try {
rec = rb.buildRecommender(dm, recommenderType, similarityType);
} catch (RecommenderException e) {
e.printStackTrace();
}
assertTrue(rec instanceof GenericUserBasedRecommender);
}
开发者ID:recommenders,项目名称:rival,代码行数:21,代码来源:GenericRecommenderBuilderTest.java
示例3: 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
示例4: 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
示例5: 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);
}
开发者ID:tensorchen,项目名称:rrs,代码行数:25,代码来源:RecommendController.java
示例6: intializeDelegate
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
private void intializeDelegate() {
try {
//iterate over all user ids
LongPrimitiveIterator it = easyrecDataModelDelegate.getUserIDs();
FastByIDMap<PreferenceArray> preferences = new FastByIDMap<PreferenceArray>(easyrecDataModelDelegate.getNumUsers());
FastByIDMap<FastByIDMap<Long>> timestamps = new FastByIDMap<FastByIDMap<Long>>(easyrecDataModelDelegate.getNumUsers());
while (it.hasNext()) {
Long userId = it.next();
//get preferences for each user
PreferenceArray prefs = easyrecDataModelDelegate.getPreferencesFromUser(userId);
preferences.put(userId,prefs);
//get preference times for each user
FastByIDMap<Long> timestampsForUser = new FastByIDMap<Long>(prefs.getIDs().length);
for (Long itemId: prefs.getIDs()) {
timestampsForUser.put(itemId,easyrecDataModelDelegate.getPreferenceTime(userId, itemId));
}
timestamps.put(userId, timestampsForUser);
}
//generate GenericDataModel
setMaxPreference(easyrecDataModelDelegate.getMaxPreference());
setMinPreference(easyrecDataModelDelegate.getMinPreference());
this.inMemoryDelegate = new GenericDataModel(preferences,timestamps);
} catch (TasteException e) {
logger.warn("caught exception while reading preference data", e);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:27,代码来源:EasyrecInMemoryDataModel.java
示例7: 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);
}
}
开发者ID:balarj,项目名称:rmend-be,代码行数:26,代码来源:GoogleDatastoreDataModel.java
示例8: DataModelWrapper
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
/**
* Constructs the wrapper using the provided model.
*
* @param model the model to be used to create the wrapped model
*/
public DataModelWrapper(final net.recommenders.rival.core.TemporalDataModelIF<Long, Long> model) {
FastByIDMap<Collection<Preference>> data = new FastByIDMap<Collection<Preference>>();
FastByIDMap<FastByIDMap<Long>> timestampData = new FastByIDMap<FastByIDMap<Long>>();
for (Long u : model.getUsers()) {
List<Preference> prefs = new ArrayList<Preference>();
FastByIDMap<Long> userTimestamps = new FastByIDMap<Long>();
timestampData.put(u, userTimestamps);
for (Long i : model.getUserItems(u)) {
Iterable<Long> timestamps = model.getUserItemTimestamps(u, i);
long t = -1;
if (timestamps != null) {
for (Long tt : timestamps) {
t = tt;
break;
}
}
userTimestamps.put(i, t);
prefs.add(new GenericPreference(u, i, model.getUserItemPreference(u, i).floatValue()));
}
data.put(u, prefs);
}
FastByIDMap<PreferenceArray> userData = GenericDataModel.toDataMap(data, true);
wrapper = new GenericDataModel(userData, timestampData);
}
开发者ID:recommenders,项目名称:rival,代码行数:31,代码来源:DataModelWrapper.java
示例9: testBuildDefaultRecommender
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Test
public void testBuildDefaultRecommender() {
RecommenderBuilder rb = new GenericRecommenderBuilder();
FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));
DataModel dm = new GenericDataModel(userData);
Recommender rec = null;
try {
rec = rb.buildRecommender(dm);
} catch (TasteException e) {
e.printStackTrace();
}
assertTrue(rec instanceof RandomRecommender);
}
开发者ID:recommenders,项目名称:rival,代码行数:20,代码来源:GenericRecommenderBuilderTest.java
示例10: getPreferencesFromUser
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
/**
* @param userID ID of user to get prefs for
* @return user's preferences, ordered by item ID
* @throws org.apache.mahout.cf.taste.common.NoSuchUserException
* if the user does not exist
* @throws TasteException if an error occurs while accessing the data
*/
public PreferenceArray getPreferencesFromUser(long userID) throws TasteException {
if (hasRatingValues) {
return mahoutDataModelMappingDAO.getPreferencesFromUser(tenantId, cutoffDate, userID, actionTypeId);
} else {
return mahoutDataModelMappingDAO.getBooleanPreferencesFromUser(tenantId, cutoffDate, userID, actionTypeId);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:15,代码来源:EasyrecDataModel.java
示例11: getPreferencesForItem
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
/**
* @param itemID item ID
* @return all existing Preference's expressed for that item, ordered by user ID, as an array
* @throws org.apache.mahout.cf.taste.common.NoSuchItemException
* if the item does not exist
* @throws TasteException if an error occurs while accessing the data
*/
public PreferenceArray getPreferencesForItem(long itemID) throws TasteException {
if (hasRatingValues) {
return mahoutDataModelMappingDAO.getPreferencesForItem(tenantId, cutoffDate, itemID, actionTypeId);
} else {
return mahoutDataModelMappingDAO.getBooleanPreferencesForItem(tenantId, cutoffDate, itemID, actionTypeId);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:15,代码来源:EasyrecDataModel.java
示例12: getPreferencesFromUser
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Override
public PreferenceArray getPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
try {
return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericPreferenceRowMapper));
} catch (EmptyResultDataAccessException e) {
logger.warn("An error occurred!", e);
throw new NoSuchUserException(userID);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:12,代码来源:MahoutDataModelMappingDAOMysqlImpl.java
示例13: getBooleanPreferencesFromUser
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Override
public PreferenceArray getBooleanPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
try {
return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericBooleanPreferenceRowMapper));
} catch (EmptyResultDataAccessException e) {
logger.warn("An error occurred!", e);
throw new NoSuchUserException(userID);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:12,代码来源:MahoutDataModelMappingDAOMysqlImpl.java
示例14: getPreferencesForItem
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Override
public PreferenceArray getPreferencesForItem(int tenantId, Date cutoffDate, long itemID, int actionTypeId) throws TasteException {
Object[] args = new Object[]{tenantId, cutoffDate, itemID, actionTypeId};
int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
try {
return new GenericItemPreferenceArray(getJdbcTemplate().query(getPreferencesForItemQuery, args, argTypes, genericPreferenceRowMapper));
} catch (EmptyResultDataAccessException e) {
logger.warn("An error occurred!", e);
throw new NoSuchItemException(itemID);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:13,代码来源:MahoutDataModelMappingDAOMysqlImpl.java
示例15: getBooleanPreferencesForItem
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Override
public PreferenceArray getBooleanPreferencesForItem(int tenantId, Date cutoffDate, long itemID, int actionTypeId) throws TasteException {
Object[] args = new Object[]{tenantId, cutoffDate, itemID, actionTypeId};
int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
try {
return new GenericItemPreferenceArray(getJdbcTemplate().query(getPreferencesForItemQuery, args, argTypes, genericBooleanPreferenceRowMapper));
} catch (EmptyResultDataAccessException e) {
logger.warn("An error occurred!", e)
throw new NoSuchItemException(itemID);
}
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:13,代码来源:MahoutDataModelMappingDAOMysqlImpl.java
示例16: testEasyrecDataModel_getPreferencesForItem
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Test
public void testEasyrecDataModel_getPreferencesForItem() throws TasteException {
EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, RATE_ACTION_TYPE_ID, HAS_RATING_VALUES, mahoutDataModelMappingDAO);
PreferenceArray preferences = easyrecDataModel.getPreferencesForItem(1);
String ids = "";
for (long id : preferences.getIDs()) {
ids += id;
}
assertEquals("12", ids);
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:14,代码来源:EasyrecDataModelTest.java
示例17: testEasyrecDataModel_getPreferencesFromUser
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Test
public void testEasyrecDataModel_getPreferencesFromUser() throws TasteException {
EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, RATE_ACTION_TYPE_ID, HAS_RATING_VALUES, mahoutDataModelMappingDAO);
PreferenceArray preferences = easyrecDataModel.getPreferencesFromUser(1);
String ids = "";
for (long id : preferences.getIDs()) {
ids += id;
}
assertEquals("123", ids);
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:13,代码来源:EasyrecDataModelTest.java
示例18: testEasyrecDataModel_getBooleanPreferencesForItem
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Test
public void testEasyrecDataModel_getBooleanPreferencesForItem() throws TasteException {
EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, BUY_ACTION_TYPE_ID, HAS_NO_RATING_VALUES, mahoutDataModelMappingDAO);
PreferenceArray preferences = easyrecDataModel.getPreferencesForItem(10);
String ids = "";
for (long id : preferences.getIDs()) {
ids += id;
}
assertEquals("12", ids);
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:14,代码来源:EasyrecDataModelTest.java
示例19: testEasyrecDataModel_getBooleanPreferencesFromUser
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Test
public void testEasyrecDataModel_getBooleanPreferencesFromUser() throws TasteException {
EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, BUY_ACTION_TYPE_ID, HAS_NO_RATING_VALUES, mahoutDataModelMappingDAO);
PreferenceArray preferences = easyrecDataModel.getPreferencesFromUser(1);
String ids = "";
for (long id : preferences.getIDs()) {
ids += id;
}
assertEquals("102030", ids);
}
开发者ID:major2015,项目名称:easyrec_major,代码行数:13,代码来源:EasyrecDataModelTest.java
示例20: getPreferencesFromUser
import org.apache.mahout.cf.taste.model.PreferenceArray; //导入依赖的package包/类
@Override
public PreferenceArray getPreferencesFromUser(int tenantId, Date cutoffDate, long userID, int actionTypeId) throws TasteException {
Object[] args = new Object[]{tenantId, cutoffDate, userID, actionTypeId};
int[] argTypes = new int[]{Types.INTEGER, Types.TIMESTAMP, Types.INTEGER, Types.INTEGER};
try {
return new GenericUserPreferenceArray(getJdbcTemplate().query(getPreferencesFromUserQuery, args, argTypes, genericPreferenceRowMapper));
} catch (EmptyResultDataAccessException e) {
throw new NoSuchUserException(userID);
}
}
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:11,代码来源:MahoutDataModelMappingDAOMysqlImpl.java
注:本文中的org.apache.mahout.cf.taste.model.PreferenceArray类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论