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


Java ThresholdUserNeighborhood类代码示例

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


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

示例1: buildRecommend

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
public void buildRecommend(String taskName) {
    String itemmodelsPath = RecommendConfig.class.getResource("/").getPath() + "itemmodels.csv";
    HadoopUtil.download(taskName, itemmodelsPath, true);
    try {
        DataModel dataModel = new FileDataModel(new File(itemmodelsPath));
        UserSimilarity similarity = new SpearmanCorrelationSimilarity(dataModel);
        UserNeighborhood userNeighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel);
        LongPrimitiveIterator userIDs = dataModel.getUserIDs();
        while (userIDs.hasNext()) {
            Long userID = userIDs.nextLong();
            long[] neighborhoods = userNeighborhood.getUserNeighborhood(userID);
            for (long neighborhood : neighborhoods) {
                double userSimilarity = similarity.userSimilarity(userID, neighborhood);
                System.out.printf("(%s,%s,%f)", userID, neighborhood, userSimilarity);
                System.out.println();
            }
        }
    } catch (TasteException | IOException e) {
        log.error(e);
    }
}
 
开发者ID:babymm,项目名称:mmsns,代码行数:22,代码来源:MahoutRecommender.java

示例2: main

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
public static void main( String[] args ) throws IOException, TasteException
{
	//user based recommender model
	DataModel model = new FileDataModel(new File("data/dataset.csv"));    	
	UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
	UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
	UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
	List<RecommendedItem> recommendations = recommender.recommend(2, 3);
	for (RecommendedItem recommendation : recommendations) {
	  System.out.println(recommendation);
	}
}
 
开发者ID:PacktPublishing,项目名称:Building-Recommendation-Engines,代码行数:13,代码来源:UserbasedRecommender.java

示例3: getStudentNeighborhood

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
@Override
@Cacheable(STUDENT_NEIGHBORHOOD_CACHE_NAME)
public UserNeighborhood getStudentNeighborhood() {
    DataModel model = buildDataModel();
    UserSimilarity similarity = buildSimilarityIndex(model);

    return new ThresholdUserNeighborhood(0.3, similarity, model);
}
 
开发者ID:university-information-system,项目名称:uis,代码行数:9,代码来源:StudentNeighborhoodStoreImpl.java

示例4: mahoutSlopeoneGeneratorTest_testBoolRecommender

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
@Test
public void mahoutSlopeoneGeneratorTest_testBoolRecommender() throws TasteException {
    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, BUY_ACTION_TYPE_ID, false, mahoutDataModelMappingDAO);
    /*TanimotoCoefficientSimilarity is intended for "binary" data sets  where a user either expresses a generic "yes" preference for an item or has no preference.*/
    UserSimilarity userSimilarity = new TanimotoCoefficientSimilarity(easyrecDataModel);

    /*ThresholdUserNeighborhood is preferred in situations where we go in for a  similarity measure between neighbors and not any number*/
    UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1d, userSimilarity, easyrecDataModel);

    /*GenericBooleanPrefUserBasedRecommender is appropriate for use when no notion of preference value exists in the data. */
    Recommender recommender = new GenericBooleanPrefUserBasedRecommender(easyrecDataModel, neighborhood, userSimilarity);

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

示例5: buildRecommender

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
@Override
public UserBasedRecommender buildRecommender(DataModel dataModel) throws TasteException {

    UserNeighborhood neighborhood =
            new ThresholdUserNeighborhood(
                    0.1, new PearsonCorrelationSimilarity(dataModel), dataModel);

    return new GenericBooleanPrefUserBasedRecommender(
            dataModel,
            neighborhood,
            similarity);
}
 
开发者ID:balarj,项目名称:rmend-be,代码行数:13,代码来源:CFRecommender.java

示例6: userNeighborhood

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
public static UserNeighborhood userNeighborhood(NEIGHBORHOOD type, UserSimilarity s, DataModel m, double num) throws TasteException {
    switch (type) {
        case NEAREST:
            /**
             * 根据数量构建最近的距离
             */
            return new NearestNUserNeighborhood((int) num, s, m);
        case THRESHOLD:
        default:
            /**
             * 根据百分比去构建
             */
            return new ThresholdUserNeighborhood(num, s, m);
    }
}
 
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:16,代码来源:RecommendFactory.java

示例7: getNeighborhood

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
/**
 * Get the user neighborhood instance, with the correct neighborhood size and algorithm
 * as specified during the construction of this RecommendEntityServlet.
 * @param similarity The similarity to form the neighborhood
 * @param model The database model to get the neighborhood of
 * @return The UserNeighborhood instance
 * @throws Exception If an exception is thrown by Mahout it is forwarded upwards.
 */
private UserNeighborhood getNeighborhood(UserSimilarity similarity, DataModel model) throws TasteException {
    if(this.neighborhoodAlg.equalsIgnoreCase(N_THRESHOLD)){
        return new ThresholdUserNeighborhood(this.neighborhoodSize, similarity, model);
    } else if(this.neighborhoodAlg.equalsIgnoreCase(N_NUSER) || this.neighborhoodAlg == null){ // == null is the default case
        return new NearestNUserNeighborhood((int)this.neighborhoodSize, similarity, model);
    } else {
        throw new TasteException("Unknown neighborhood algorithm type: " + this.neighborhoodAlg);
    }
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:18,代码来源:RecommendEntityServlet.java

示例8: getRecommenderItem

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
public static String getRecommenderItem(int id) throws IOException, TasteException {
		//DB연동 
		MysqlDataSource datasource = new MysqlDataSource();
		datasource.setServerName("localhost");
		datasource.setUser("root");
		datasource.setPassword("465651");
		datasource.setDatabaseName("tourOfAll2");
		
		
		DataModel model = new ReloadFromJDBCDataModel(new MySQLJDBCDataModel(datasource, "evaluations", "user_id", "item_id", "score", null));
		// DataModel model = new FileDataModel(
		// new
		// File("C:/Users/Administrator/git/RestfulMahoutRecommender/RestfulRecommenderApi/src/main/resources/ddd.csv"));
		
		//유사도 측정을 캐쉬로 저장
		UserSimilarity similarity = new CachingUserSimilarity(new EuclideanDistanceSimilarity(model),model);

		// new SpearmanCorrelationSimilarity(model);
		
		//유저 이웃 계산 결과를 캐쉬로 저장
		UserNeighborhood neighborhood = new CachingUserNeighborhood(new ThresholdUserNeighborhood(0.75, similarity, model),model);
		
		
		// new NearestNUserNeighborhood(5,similarity,model);
		Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

		LoadEvaluator.runLoad(recommender);

		
		String json = "{" + "\"Items\"" + ":" + "[";

		IDRescorer testRescorer = new GenreRescorer(id);
		List<RecommendedItem> recommendations = recommender.recommend(id, 20, testRescorer);
		
//		List<RecommendedItem> recommendations = recommender.recommend(id, 10);
		// String Parsing 아이디값만 찾음
		Iterator<RecommendedItem> itr = recommendations.iterator();
		while (itr.hasNext()) {
			RecommendedItem item = itr.next();
			String str = item.toString();
			String ItemId = str.substring(str.indexOf(":") + 1, str.indexOf(","));
			String value = str.substring(str.indexOf("value:") + 6, str.indexOf("value:") + 9);
			getPlaceURL url = new getPlaceURL(Integer.parseInt(ItemId));
			GetPlaceTitle title = new GetPlaceTitle(Integer.parseInt(ItemId));
			if (itr.hasNext())
				json = json + "{" + "\"ID\"" + ":" + "\"" + ItemId + "\"" 
			            + ", " + "\"Value\"" + ":" + "\"" + value + "\""
			            + ", " + "\"URL\"" + ":" + "\"" + url.getURL() + "\""
			            + ", " + "\"Title\"" + ":" + "\"" + title.getTitle() + "\""
			            + "}" + ", ";
			else
				json = json + "{" + "\"ID\"" + ":" + "\"" + ItemId + "\""
						+ ", " + "\"Value\"" + ":" + "\"" + value + "\""
						+ ", " + "\"URL\"" + ":" + "\"" + url.getURL() + "\""
						+ ", " + "\"Title\"" + ":" + "\"" + title.getTitle() + "\""
						+ "}";
		}

		json = json + "]" + "}";
		return (json);
	}
 
开发者ID:bcc829,项目名称:RestfulMahoutRecommender,代码行数:62,代码来源:mahoutRecommneder.java

示例9: buildRecommender

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
public Recommender buildRecommender(DataModel dataModel) throws TasteException {
    UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
    UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel);

    return new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
}
 
开发者ID:novatrixtech,项目名称:drnutrix-api,代码行数:7,代码来源:RecommendationBuilder.java

示例10: getThreshold

import org.apache.mahout.cf.taste.impl.neighborhood.ThresholdUserNeighborhood; //导入依赖的package包/类
public static UserNeighborhood getThreshold(DataModel dataModel, UserSimilarity userSimilarity,
		double threshold) throws TasteException {
	System.out.println("Threshold");
	return new ThresholdUserNeighborhood(threshold, userSimilarity, dataModel);
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:6,代码来源:RecommParametersMeasures.java


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