• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java IDRescorer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: next

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public RecommendedItem next() {
  FastByIDFloatMap.MapEntry entry = countsIterator.next();
  long id = entry.getKey();
  float value = entry.getValue();
  IDRescorer theRescorer = rescorer;
  if (theRescorer != null) {
    if (theRescorer.isFiltered(id)) {
      return null;
    }
    value = (float) theRescorer.rescore(id, value);
    if (!LangUtils.isFinite(value)) {
      return null;
    }
  }
  delegate.set(id, value);
  return delegate;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:19,代码来源:MostPopularItemsIterator.java


示例2: testMultiRecommendRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Test
public void testMultiRecommendRescorer() {
  RescorerProvider multi = 
      new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
  
  IDRescorer provider = multi.getRecommendRescorer(new long[]{5}, (MyrrixRecommender) null);
  assertNull(provider);
  
  provider = multi.getRecommendRescorer(new long[]{2}, (MyrrixRecommender) null);
  assertNotNull(provider);
  assertFalse(provider instanceof MultiRescorer);
  assertTrue(provider.isFiltered(3));
  assertFalse(provider.isFiltered(2));

  provider = multi.getRecommendRescorer(new long[]{6}, (MyrrixRecommender) null);
  assertNotNull(provider);
  assertTrue(provider instanceof MultiRescorer);
  assertTrue(provider.isFiltered(3));
  assertTrue(provider.isFiltered(2));
  assertFalse(provider.isFiltered(12));
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:22,代码来源:MultiRescorerProviderTest.java


示例3: testMultiRecommendToAnonymousRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Test
public void testMultiRecommendToAnonymousRescorer() {
  RescorerProvider multi = 
      new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
  
  IDRescorer provider = multi.getRecommendToAnonymousRescorer(new long[]{5}, (MyrrixRecommender) null);
  assertNull(provider);
  
  provider = multi.getRecommendToAnonymousRescorer(new long[]{2}, (MyrrixRecommender) null);
  assertNotNull(provider);
  assertFalse(provider instanceof MultiRescorer);
  assertTrue(provider.isFiltered(3));
  assertFalse(provider.isFiltered(2));

  provider = multi.getRecommendToAnonymousRescorer(new long[]{6}, (MyrrixRecommender) null);
  assertNotNull(provider);
  assertTrue(provider instanceof MultiRescorer);
  assertTrue(provider.isFiltered(3));
  assertTrue(provider.isFiltered(2));
  assertFalse(provider.isFiltered(12));
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:22,代码来源:MultiRescorerProviderTest.java


示例4: doGet

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
  MyrrixRecommender recommender = getRecommender();
  RescorerProvider rescorerProvider = getRescorerProvider();
  try {
    IDRescorer rescorer = rescorerProvider == null ? null :
        rescorerProvider.getMostPopularItemsRescorer(recommender, getRescorerParams(request));
    output(request, response, recommender.mostPopularItems(getHowMany(request), rescorer));
  } catch (NotReadyException nre) {
    response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
  } catch (TasteException te) {
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
    getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
  } catch (IllegalArgumentException iae) {
    response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:18,代码来源:MostPopularItemsServlet.java


示例5: itemBased

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
public static ItemBasedRecommender itemBased() throws Exception {

		// Load the data
		StringItemIdFileDataModel dataModel = loadFromFile("data/BX-Book-Ratings.csv", ";");
		// Collection<GenericItemSimilarity.ItemItemSimilarity> correlations =
		// null;
		// ItemItemSimilarity iis = new ItemItemSimilarity(0, 0, 0);
		// ItemSimilarity itemSimilarity = new
		// GenericItemSimilarity(correlations);
		ItemSimilarity itemSimilarity = new PearsonCorrelationSimilarity(dataModel);

		ItemBasedRecommender recommender = new GenericItemBasedRecommender(
				dataModel, itemSimilarity);

		IDRescorer rescorer = new MyRescorer();

		// List recommendations = recommender.recommend(2, 3, rescorer);
		String itemISBN = "042513976X";
		long itemID = dataModel.readItemIDFromString(itemISBN);
		int noItems = 10;

		System.out.println("Recommendations for item: " + books.get(itemISBN));

		System.out.println("\nMost similar items:");
		List<RecommendedItem> recommendations = recommender.mostSimilarItems(
				itemID, noItems);
		for (RecommendedItem item : recommendations) {
			itemISBN = dataModel.getItemIDAsString(item.getItemID());
			System.out.println("Item: " + books.get(itemISBN) + " | Item id: "
					+ itemISBN + " | Value: " + item.getValue());
		}
		
		return recommender;
	}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:35,代码来源:BookRecommender.java


示例6: getRecommendRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public IDRescorer getRecommendRescorer(long[] userIDs, MyrrixRecommender recommender, String... args) {
  if (args == null || args.length == 0) {
    return null;
  }
  long toItemID = Long.parseLong(args[0]);
  return new SimilarToItemRescorer(toItemID, recommender);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:9,代码来源:SimilarToItemRescorerProvider.java


示例7: recommendToAnonymous

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public List<RecommendedItem> recommendToAnonymous(long[] itemIDs,
                                                  float[] values,
                                                  int howMany,
                                                  IDRescorer rescorer)
    throws NotReadyException, NoSuchItemException {

  Preconditions.checkArgument(howMany > 0, "howMany must be positive");

  float[] anonymousUserFeatures = buildAnonymousUserFeatures(itemIDs, values);

  FastIDSet userKnownItemIDs = new FastIDSet(itemIDs.length);
  for (long itemID : itemIDs) {
    userKnownItemIDs.add(itemID);
  }

  float[][] anonymousFeaturesAsArray = { anonymousUserFeatures };

  Generation generation = getCurrentGeneration();    
  Lock yLock = generation.getYLock().readLock();    
  yLock.lock();
  try {
    return multithreadedTopN(anonymousFeaturesAsArray,
                             userKnownItemIDs,
                             generation.getUserTagIDs(),
                             rescorer,
                             howMany,
                             generation.getCandidateFilter());
  } finally {
    yLock.unlock();
  }
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:33,代码来源:ServerRecommender.java


示例8: RecommendIterator

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
RecommendIterator(float[][] features,
                  Iterator<FastByIDMap.MapEntry<float[]>> Yiterator,
                  FastIDSet knownItemIDs,
                  FastIDSet userTagIDs,
                  IDRescorer rescorer) {
  Preconditions.checkArgument(features.length > 0, "features must not be empty");
  delegate = new MutableRecommendedItem();
  this.features = features;
  this.Yiterator = Yiterator;
  this.knownItemIDs = knownItemIDs;
  this.userTagIDs = userTagIDs;
  this.rescorer = rescorer;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:14,代码来源:RecommendIterator.java


示例9: rescore

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public double rescore(long itemID, double value) {
  for (IDRescorer rescorer : rescorers) {
    value = rescorer.rescore(itemID, value);
    if (Double.isNaN(value)) {
      return Double.NaN;
    }
  }
  return value;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:11,代码来源:MultiRescorer.java


示例10: isFiltered

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public boolean isFiltered(long itemID) {
  for (IDRescorer rescorer : rescorers) {
    if (rescorer.isFiltered(itemID)) {
      return true;
    }
  }
  return false;
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:10,代码来源:MultiRescorer.java


示例11: getRecommendRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public IDRescorer getRecommendRescorer(long[] userIDs, MyrrixRecommender recommender, String... args) {
  List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
  for (RescorerProvider provider : providers) {
    IDRescorer rescorer = provider.getRecommendRescorer(userIDs, recommender, args);
    if (rescorer != null) {
      rescorers.add(rescorer);
    }
  }
  return buildRescorer(rescorers);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:12,代码来源:MultiRescorerProvider.java


示例12: getRecommendToAnonymousRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public IDRescorer getRecommendToAnonymousRescorer(long[] itemIDs, MyrrixRecommender recommender, String... args) {
  List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
  for (RescorerProvider provider : providers) {
    IDRescorer rescorer = provider.getRecommendToAnonymousRescorer(itemIDs, recommender, args);
    if (rescorer != null) {
      rescorers.add(rescorer);
    }
  }
  return buildRescorer(rescorers);  
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:12,代码来源:MultiRescorerProvider.java


示例13: getMostPopularItemsRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Override
public IDRescorer getMostPopularItemsRescorer(MyrrixRecommender recommender, String... args) {
  List<IDRescorer> rescorers = Lists.newArrayListWithCapacity(providers.length);
  for (RescorerProvider provider : providers) {
    IDRescorer rescorer = provider.getMostPopularItemsRescorer(recommender, args);
    if (rescorer != null) {
      rescorers.add(rescorer);
    }
  }
  return buildRescorer(rescorers); 
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:12,代码来源:MultiRescorerProvider.java


示例14: buildRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
private static IDRescorer buildRescorer(List<IDRescorer> rescorers) {
  int numRescorers = rescorers.size();
  if (numRescorers == 0) {
    return null;
  }
  if (numRescorers == 1) {
    return rescorers.get(0);
  }
  return new MultiRescorer(rescorers);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:11,代码来源:MultiRescorerProvider.java


示例15: testMultiMostPopularItemsRescorer

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Test
public void testMultiMostPopularItemsRescorer() {
  RescorerProvider multi = 
      new MultiRescorerProvider(new SimpleModRescorerProvider(2), new SimpleModRescorerProvider(3));
  IDRescorer provider = multi.getMostPopularItemsRescorer(null);
  assertNotNull(provider);
  assertTrue(provider instanceof MultiRescorer);
  assertTrue(provider.isFiltered(3));
  assertTrue(provider.isFiltered(2));
  assertFalse(provider.isFiltered(6));    
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:12,代码来源:MultiRescorerProviderTest.java


示例16: recommend

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
/**
 * {@link Rescorer}s are not available at this time in the model.
 *
 * @return {@link #recommend(long, int)} if rescorer is null
 * @throws UnsupportedOperationException otherwise
 * @deprecated use {@link #recommend(long, int)} instead
 */
@Deprecated
@Override
public List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer)
    throws TasteException {
  if (rescorer != null) {
    throw new UnsupportedOperationException();
  }
  return recommend(userID, howMany);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:17,代码来源:ClientRecommender.java


示例17: recommendToMany

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
@Deprecated
@Override
public List<RecommendedItem> recommendToMany(long[] userIDs,
                                             int howMany,
                                             boolean considerKnownItems,
                                             IDRescorer rescorer) throws TasteException {
  if (rescorer != null) {
    throw new UnsupportedOperationException();
  }
  return recommendToMany(userIDs, howMany, considerKnownItems, (String[]) null);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:12,代码来源:ClientRecommender.java


示例18: recommendToAnonymous

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
/**
 * Note that {@link IDRescorer} is not supported in the client now and must be null.
 *
 * @return {@link #recommendToAnonymous(long[], int)} if rescorer is null
 * @throws UnsupportedOperationException otherwise
 * @deprecated use {@link #recommendToAnonymous(long[], int)} instead
 */
@Deprecated
@Override
public List<RecommendedItem> recommendToAnonymous(long[] itemIDs,
                                                  int howMany,
                                                  IDRescorer rescorer) throws TasteException {
  if (rescorer != null) {
    throw new UnsupportedOperationException();
  }
  return recommendToAnonymous(itemIDs, howMany);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:18,代码来源:ClientRecommender.java


示例19: mostPopularItems

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的package包/类
/**
 * Note that {@link IDRescorer} is not supported in the client now and must be null.
 *
 * @return {@link #mostPopularItems(int)} if rescorer is null
 * @throws UnsupportedOperationException otherwise
 * @deprecated use {@link #mostPopularItems(int)} instead
 */
@Deprecated
@Override
public List<RecommendedItem> mostPopularItems(int howMany, IDRescorer rescorer) throws TasteException {
  if (rescorer != null) {
    throw new UnsupportedOperationException();
  }
  return mostPopularItems(howMany);
}
 
开发者ID:myrrix,项目名称:myrrix-recommender,代码行数:16,代码来源:ClientRecommender.java


示例20: getRecommenderItem

import org.apache.mahout.cf.taste.recommender.IDRescorer; //导入依赖的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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Session类代码示例发布时间:2022-05-23
下一篇:
Java ConstantUtf8类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap