本文整理汇总了Java中org.apache.mahout.cf.taste.impl.recommender.CachingRecommender类的典型用法代码示例。如果您正苦于以下问题:Java CachingRecommender类的具体用法?Java CachingRecommender怎么用?Java CachingRecommender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CachingRecommender类属于org.apache.mahout.cf.taste.impl.recommender包,在下文中一共展示了CachingRecommender类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: recommend
import org.apache.mahout.cf.taste.impl.recommender.CachingRecommender; //导入依赖的package包/类
private static void recommend(String ratingsFile, int ... userIds)
throws TasteException, IOException {
DataModel model = new FileDataModel(new File(ratingsFile));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(
100, similarity, model);
Recommender recommender = new GenericUserBasedRecommender(
model, neighborhood, similarity);
Recommender cachingRecommender = new CachingRecommender(recommender);
for(int userId: userIds) {
System.out.println("UserID " + userId);
List<RecommendedItem> recommendations =
cachingRecommender.recommend(userId, 2);
for(RecommendedItem item: recommendations) {
System.out.println(" item " + item.getItemID() + " score " + item.getValue());
}
}
}
开发者ID:Hanmourang,项目名称:hiped2,代码行数:25,代码来源:MovieUserRecommender.java
示例2: main
import org.apache.mahout.cf.taste.impl.recommender.CachingRecommender; //导入依赖的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.CachingRecommender; //导入依赖的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: reconstructRecommendationCache
import org.apache.mahout.cf.taste.impl.recommender.CachingRecommender; //导入依赖的package包/类
/**
* This function will (re)construct all the recommendations using
* Mahout.
* NOTE: Be aware that this is a very expensive function in terms of
* processing time, therefore this function is called on a regular
* interval (say every x hours) to update the recommendation cache
* according to the latest data available in the database.
*/
public void reconstructRecommendationCache(){
long startTime = System.currentTimeMillis();
try {
/* Open the database and update the dictionary to Mahout style */
convertUIDToBigIntInDB();
/*
* Database is converted, generate the recommendations seperately
* from the currently cached recommendations if there are any.
*/
MySQLJDBCDataModel model = getMahoutDatabaseModel();
/*
* Build the recommender itself.
*/
Recommender userRecommender = null;
Recommender itemRecommender = null;
if(this.type == null || this.type.equalsIgnoreCase(T_USER) || this.type.equalsIgnoreCase(T_BOTH)){
userRecommender = buildRecommenderInstance(model, RecFieldType.USER);
}
if(this.type == null || this.type.equalsIgnoreCase(T_ITEM) || this.type.equalsIgnoreCase(T_BOTH)){
itemRecommender = buildRecommenderInstance(model, RecFieldType.ITEM);
}
/*
* The recommendation process has finished, replace the cached
* recommendations with the new updated version.
*/
if(this.type == null || this.type.equalsIgnoreCase(T_USER) || this.type.equalsIgnoreCase(T_BOTH)){
this.userRecommenderCache = new CachingRecommender(userRecommender);
}
if(this.type == null || this.type.equalsIgnoreCase(T_ITEM) || this.type.equalsIgnoreCase(T_BOTH)){
this.itemRecommenderCache = new CachingRecommender(itemRecommender);
}
this.lastExecutionTime = System.currentTimeMillis() - startTime;
org.webdsl.logging.Logger.info("Building the Mahout Index took: " + this.lastExecutionTime);
} catch (Exception e){
org.webdsl.logging.Logger.error("\n\n************ SEVERE ERROR ************\nThere was an exception while reconstructing the recommendations!\n" + e);
org.webdsl.logging.Logger.error("EXCEPTION",e);
org.webdsl.logging.Logger.error("************ END OF ERROR ************\n\n");
}
}
开发者ID:webdsl,项目名称:webdsl,代码行数:52,代码来源:RecommendEntityServlet.java
注:本文中的org.apache.mahout.cf.taste.impl.recommender.CachingRecommender类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论