当前位置: 首页>>代码示例>>Java>>正文


Java SlopeOneRecommender类代码示例

本文整理汇总了Java中org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender的典型用法代码示例。如果您正苦于以下问题:Java SlopeOneRecommender类的具体用法?Java SlopeOneRecommender怎么用?Java SlopeOneRecommender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SlopeOneRecommender类属于org.apache.mahout.cf.taste.impl.recommender.slopeone包,在下文中一共展示了SlopeOneRecommender类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mahoutSlopeoneGeneratorTest_testRecommender

import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender; //导入依赖的package包/类
@Test
public void mahoutSlopeoneGeneratorTest_testRecommender() throws TasteException {
    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, RATE_ACTION_TYPE_ID, true, mahoutDataModelMappingDAO);
    Recommender recommender = new SlopeOneRecommender(easyrecDataModel);

    Assert.assertEquals(3, recommender.recommend(3, 1).get(0).getItemID());
    Assert.assertEquals(10, (int) recommender.recommend(3, 1).get(0).getValue());
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:9,代码来源:MahoutSlopeoneGeneratorTest.java

示例2: main

import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender; //导入依赖的package包/类
public static void main( String[] args ) throws IOException, TasteException, OptionException
{
    CreateCsvRatingsFile();


    // create data source (model) - from the csv file
    File ratingsFile = new File(outputFile);
    DataModel model = new FileDataModel(ratingsFile);

    // create a simple recommender on our data
    CachingRecommender cachingRecommender = new CachingRecommender(new SlopeOneRecommender(model));

    // for all users
    for (LongPrimitiveIterator it = model.getUserIDs(); it.hasNext();){
        long userId = it.nextLong();

        // get the recommendations for the user
        List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 10);

        // if empty write something
        if (recommendations.size() == 0){
            System.out.print("User ");
            System.out.print(userId);
            System.out.println(": no recommendations");
        }

        // print the list of recommendations for each
        for (RecommendedItem recommendedItem : recommendations) {
            System.out.print("User ");
            System.out.print(userId);
            System.out.print(": ");
            System.out.println(recommendedItem);
        }
    }
}
 
开发者ID:pgiacome,项目名称:Apache-Mahout-cookbook,代码行数:36,代码来源:App.java

示例3: recommend

import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender; //导入依赖的package包/类
public List<RecommendedItem> recommend(int userid,int size) throws TasteException, IOException{
		List<RecommendedItem> list = null;
//		MovieDataModel model = new MovieDataModel();
		String file=ServletActionContext.getServletContext().getRealPath("/u1.base");
		DataModel model = new FileDataModel(new File(file));
		Recommender recommender = new CachingRecommender(new SlopeOneRecommender(model));
		list = recommender.recommend(userid, size);
		return list;
	}
 
开发者ID:laozhaokun,项目名称:movie_recommender,代码行数:10,代码来源:SlopeRecommender.java

示例4: doExecute

import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender; //导入依赖的package包/类
@Override
protected void doExecute(ExecutionControl executionControl, MahoutSlopeoneGeneratorStats stats) throws Exception {
    // when doExecute() is called, the generator has been initialized with the configuration we should use

    Date execution = new Date();

    MahoutSlopeoneGeneratorConfig config = getConfiguration();

    TypeMappingService typeMappingService = (TypeMappingService) super.getTypeMappingService();
    ItemAssocService itemAssocService = getItemAssocService();

    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(config.getTenantId(), typeMappingService.getIdOfActionType(config.getTenantId(), config.getActionType()), true, mahoutDataModelMappingDAO);

    Recommender recommender = new SlopeOneRecommender(easyrecDataModel);

    itemTypeDAO.insertOrUpdate(config.getTenantId(), "USER", false);

    Integer assocType = typeMappingService.getIdOfAssocType(config.getTenantId(), config.getAssociationType());
    Integer userType = typeMappingService.getIdOfItemType(config.getTenantId(), "USER");
    Integer sourceType = typeMappingService.getIdOfSourceType(config.getTenantId(), getSourceType());
    Integer viewType = typeMappingService.getIdOfViewType(config.getTenantId(), config.getViewType());

    stats.setNumberOfItems(easyrecDataModel.getNumItems());

    for (LongPrimitiveIterator it = easyrecDataModel.getUserIDs(); it.hasNext(); ) {
        long userId = it.nextLong();
        List<RecommendedItem> recommendations = recommender.recommend(userId, config.getNumberOfRecs());

        if (recommendations.isEmpty()) {
            logger.debug("User " + userId + " : no recommendations");
        }

        // print the list of recommendations for each
        for (RecommendedItem recommendedItem : recommendations) {
            logger.debug("User " + userId + " : " + recommendedItem);

            Integer itemToId = (int) recommendedItem.getItemID();
            Integer itemToType = itemDAO.getItemTypeIdOfItem(config.getTenantId(), itemToId);

            ItemVO<Integer, Integer> fromItem = new ItemVO<Integer, Integer>(config.getTenantId(), (int) userId, userType);
            Double recommendationStrength = (double) recommendedItem.getValue();
            ItemVO<Integer, Integer> toItem = new ItemVO<Integer, Integer>(config.getTenantId(), itemToId, itemToType);

            ItemAssocVO<Integer,Integer> itemAssoc = new ItemAssocVO<Integer,Integer>(
                    config.getTenantId(), fromItem, assocType, recommendationStrength, toItem, sourceType,
                    "Mahout Slopeone Generator", viewType, null, execution);

            itemAssocService.insertOrUpdateItemAssoc(itemAssoc);
            stats.incNumberOfRulesCreated();
        }
    }

}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:54,代码来源:MahoutSlopeoneGenerator.java

示例5: slopeOneRecommender

import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender; //导入依赖的package包/类
public static RecommenderBuilder slopeOneRecommender() throws TasteException {
    return dataModel -> new SlopeOneRecommender(dataModel);
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:4,代码来源:RecommendFactory.java


注:本文中的org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。