本文整理汇总了Java中org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity类的典型用法代码示例。如果您正苦于以下问题:Java LogLikelihoodSimilarity类的具体用法?Java LogLikelihoodSimilarity怎么用?Java LogLikelihoodSimilarity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogLikelihoodSimilarity类属于org.apache.mahout.cf.taste.impl.similarity包,在下文中一共展示了LogLikelihoodSimilarity类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity; //导入依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
DataModel model = new FileDataModel(new File("data/dataset.csv"));
ItemSimilarity similarity = new LogLikelihoodSimilarity(model);
//UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(model, similarity);
List<RecommendedItem> recommendations = recommender.mostSimilarItems(18, 3);
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
示例2: getSimularity
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity; //导入依赖的package包/类
/**
* Get the similarity instance that is used to check which users and items
* are similar. There are several implementations for this, these are specified
* by the this.alg value of the RecommendEntityServlet instance.
* NOTE: Since there are two interfaces: ItemSimilarity and UserSimilarity the
* returned type is of the interface Refreshable since both interfaces inherit
* that type as well. Cast it to the right type.
* @param model The database model to use for the similarity calculations
* @return The UserSimilarity or ItemSimilarity instance.
* @throws TasteException If an exception is thrown by Mahout it is forwarded upwards.
*/
private Refreshable getSimularity(DataModel model) throws TasteException {
if(this.alg.equalsIgnoreCase(A_EUCLIDEAN)){
return new EuclideanDistanceSimilarity(model);
} else if(this.alg.equalsIgnoreCase(A_PEARSON)){
return new PearsonCorrelationSimilarity(model);
} else if(this.alg.equalsIgnoreCase(A_TANIMOTO)){
return new TanimotoCoefficientSimilarity(model);
} else if(this.alg.equalsIgnoreCase(A_LOGLIKELIHOOD) || this.alg == null){ // == null is the default case
return new LogLikelihoodSimilarity(model);
} else {
throw new TasteException("Unknown algorithm type: " + this.alg);
}
}
示例3: recommend
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity; //导入依赖的package包/类
@ResponseBody
@RequestMapping(value = "/recommend/user/{userId}", method = RequestMethod.GET)
public String recommend(@PathVariable Long userId
) throws TasteException, IOException {
DataModel dataModel = getFileDataModel();
UserSimilarity userSimilarity =
// new PearsonCorrelationSimilarity(dataModel); //皮尔逊相关系数
// new EuclideanDistanceSimilarity(dataModel); //欧氏距离
// new TanimotoCoefficientSimilarity(dataModel); //谷本系数
new LogLikelihoodSimilarity(dataModel); //对数似然比
// userSimilarity.setPreferenceInferrer(new AveragingPreferenceInferrer(dataModel));
UserNeighborhood userNeighborhood =
new NearestNUserNeighborhood(10, userSimilarity, dataModel);
Recommender recommender =
//new GenericUserBasedRecommender(dataModel, userNeighborhood, userSimilarity);
new SVDRecommender(dataModel, new ALSWRFactorizer(dataModel, 10, 0.05, 10));
List<RecommendedItem> recommendedItems =
recommender.recommend(userId, 10);
Gson gson = new Gson();
List<RecommendResultVO> recommendResultVOs =
new ArrayList<RecommendResultVO>(recommendedItems.size());
for (int i = 0; i < recommendedItems.size(); i++) {
RecommendResultVO recommendResultVO = new RecommendResultVO();
recommendResultVO.setRestaurantId(recommendedItems.get(i).getItemID());
recommendResultVO.setScore(recommendedItems.get(i).getValue());
recommendResultVOs.add(i, recommendResultVO);
}
return gson.toJson(recommendResultVOs);
}
示例4: recommendByFood
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity; //导入依赖的package包/类
@ResponseBody
@RequestMapping(value = "/recommend/user/{userId}/food/{foodId}", method = RequestMethod.GET)
public String recommendByFood(@PathVariable Long userId, @PathVariable Long foodId
) throws TasteException, IOException {
DataModel dataModel = getFileDataModel();
UserSimilarity userSimilarity =
new LogLikelihoodSimilarity(dataModel); //对数似然比
UserNeighborhood userNeighborhood =
new NearestNUserNeighborhood(10, userSimilarity, dataModel);
Recommender recommender =
new SVDRecommender(dataModel, new ALSWRFactorizer(dataModel, 10, 0.05, 10));
List<RecommendedItem> recommendedItems =
recommender.recommend(userId, 1000);
Gson gson = new Gson();
List<RecommendResultVO> recommendResultVOs =
new ArrayList<RecommendResultVO>();
for (int i = 0; i < recommendedItems.size(); i++) {
List<RestaurantFood> rfList = restaurantFoodService.
getRestaurantFoodsByRestaurantId(recommendedItems.get(i).getItemID());
for (RestaurantFood restaurantFood : rfList) {
if (restaurantFood.getFoodId() == foodId) {
RecommendResultVO recommendResultVO = new RecommendResultVO();
recommendResultVO.setRestaurantId(recommendedItems.get(i).getItemID());
recommendResultVO.setScore(recommendedItems.get(i).getValue());
recommendResultVOs.add(recommendResultVO);
}
}
}
return gson.toJson(recommendResultVOs);
}
示例5: analyze
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity; //导入依赖的package包/类
/**
* <b>[推薦の評価方法]</b><br>
* cf.)70%のデータを使用してレコメンダーを生成→30%のデータを使用して評価
*
* @param dataModel
* @throws TasteException
*/
@Override
public void analyze() throws TasteException {
// アイテムの類似性を定義
super.i("◆ ITEM ======= Start ======");
super.i("◆ -------------------------");
try {
final Map<ItemName, ItemAffinityVO> itemMap = super.dto.itemMap;
// 谷本係数
ItemSimilarity a_tanimoto = new TanimotoCoefficientSimilarity(super.dataModel);
ItemAffinityVO tanimoto = itemMap.get(ItemName.TANIMOTO);
recommend(super.dataModel, a_tanimoto, tanimoto);
// シティブロック距離
ItemSimilarity a_cityBlock = new CityBlockSimilarity(super.dataModel);
ItemAffinityVO cityBlock = itemMap.get(ItemName.CITY_BLOCK);
recommend(super.dataModel, a_cityBlock, cityBlock);
// 稀にしか起こらない事象
ItemSimilarity a_logLikelihood = new LogLikelihoodSimilarity(super.dataModel);
ItemAffinityVO logLike = itemMap.get(ItemName.LOG_LIKE);
recommend(super.dataModel, a_logLikelihood, logLike);
// ユークリッド距離
ItemSimilarity a_euclid = new org.apache.mahout.cf.taste.impl.similarity.EuclideanDistanceSimilarity(super.dataModel);
ItemAffinityVO euclidean = itemMap.get(ItemName.EUCLIDEAN);
recommend(super.dataModel, a_euclid, euclidean);
// コサイン類似度
ItemSimilarity a_cosine = new org.apache.mahout.cf.taste.impl.similarity.UncenteredCosineSimilarity(super.dataModel);
ItemAffinityVO cosine = itemMap.get(ItemName.COSINE);
recommend(super.dataModel, a_cosine, cosine);
} catch (IllegalArgumentException e) {
}
super.i("◆ -------------------------");
super.iln("◆ ITEM ======= END ======");
}
示例6: getLogLikelihoodSimilarity
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity; //导入依赖的package包/类
public static LogLikelihoodSimilarity getLogLikelihoodSimilarity(DataModel dataModel)
throws TasteException {
System.out.println("LogLikelihoodSimilarity");
return new LogLikelihoodSimilarity(dataModel);
}