本文整理汇总了Java中org.apache.mahout.cf.taste.recommender.ItemBasedRecommender类的典型用法代码示例。如果您正苦于以下问题:Java ItemBasedRecommender类的具体用法?Java ItemBasedRecommender怎么用?Java ItemBasedRecommender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ItemBasedRecommender类属于org.apache.mahout.cf.taste.recommender包,在下文中一共展示了ItemBasedRecommender类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: run
import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender; //导入依赖的package包/类
@Override
public void run(RecommenderConfiguration configuration,
Environment environment) {
PGPoolingDataSource pgPoolingDataSource = configuration.getDataSourceFactory().build(environment);
ReloadFromJDBCDataModel dataModel = null;
try {
dataModel = configuration.getDataModelFactory().build(pgPoolingDataSource);
} catch (TasteException e) {
System.err.println(e);
System.exit(-1);
}
Recommender userBasedRecommender = configuration.getRecommenderFactory().buildUserBasedRecommender(dataModel);
ItemBasedRecommender itemBasedRecommender = configuration.getRecommenderFactory().buildItemBasedRecommender(dataModel);
final RecommendationResource userRecommendationResource = new RecommendationResource(userBasedRecommender, itemBasedRecommender);
final DataModelResource dataModelResource = new DataModelResource(dataModel);
environment.jersey().register(userRecommendationResource);
environment.jersey().register(dataModelResource);
}
开发者ID:gurelkaynak,项目名称:recommendationengine,代码行数:22,代码来源:RecommenderApplication.java
示例2: itemBased
import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender; //导入依赖的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
示例3: main
import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
String base = "C:\\Users\\smallnest\\Desktop\\test\\";
File file = new File(base + "user_movies.csv");
DoubanFileDataModel model = new DoubanFileDataModel(file);
//http://www.cnphp6.com/archives/84955
//曼哈顿相似度
//UserSimilarity similarity = new org.apache.mahout.cf.taste.impl.similarity.CityBlockSimilarity(model);
//欧几里德相似度
//UserSimilarity similarity = new org.apache.mahout.cf.taste.impl.similarity.EuclideanDistanceSimilarity(model);
//对数似然相似度
//UserSimilarity similarity = new org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity(model);
//斯皮尔曼相似度
//UserSimilarity similarity = new org.apache.mahout.cf.taste.impl.similarity.SpearmanCorrelationSimilarity(model);
//Tanimoto 相似度
//UserSimilarity similarity = new org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity(model)
//Cosine相似度
//UserSimilarity similarity = new org.apache.mahout.cf.taste.impl.similarity.UncenteredCosineSimilarity();
//皮尔逊相似度
ItemSimilarity similarity = new PearsonCorrelationSimilarity(model);
ItemBasedRecommender recommender = new GenericItemBasedRecommender(model, similarity);
BatchItemSimilarities batch = new MultithreadedBatchItemSimilarities(recommender, 5);
int numSimilarities = batch.computeItemSimilarities(Runtime.getRuntime().availableProcessors(), 1, new FileSimilarItemsWriter(new File(base + "item_result.csv")));
System.out.println("Computed " + numSimilarities + " similarities for " + model.getNumItems() + " items " + "and saved them to file " + base + "item_result.csv");
}
开发者ID:smallnest,项目名称:mahout-douban-recommender,代码行数:29,代码来源:DoubanItemBasedRecommender.java
示例4: recommend
import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender; //导入依赖的package包/类
/**
* レコメンデーションを生成して出力
*
* @param dataModel
* @param algorithm
* @throws TasteException
*/
private void recommend(DataModel dataModel, ItemSimilarity algorithm, ItemAffinityVO dto) throws TasteException {
super.i("◆ " + algorithm.getClass());
ItemBasedRecommender recommender = new GenericItemBasedRecommender(dataModel, algorithm);
List<RecommendedItem> items = recommender.recommend(dto.userId, dto.howMany);
for (RecommendedItem item : items) {
super.i("◆ " + item);
}
}
开发者ID:pollseed,项目名称:machine-learning,代码行数:16,代码来源:Item.java
示例5: buildRecommender
import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender; //导入依赖的package包/类
@Override
public ItemBasedRecommender buildRecommender(DataModel dataModel) throws TasteException {
return new GenericBooleanPrefItemBasedRecommender(dataModel, similarity);
}
开发者ID:balarj,项目名称:rmend-be,代码行数:5,代码来源:CFRecommender.java
示例6: RecommendationResource
import org.apache.mahout.cf.taste.recommender.ItemBasedRecommender; //导入依赖的package包/类
public RecommendationResource(Recommender u, ItemBasedRecommender i){
this.userBasedRecommender = u;
this.itemBasedRecommender = i;
}
开发者ID:gurelkaynak,项目名称:recommendationengine,代码行数:5,代码来源:RecommendationResource.java
注:本文中的org.apache.mahout.cf.taste.recommender.ItemBasedRecommender类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论