本文整理汇总了Java中org.apache.mahout.cf.taste.model.DataModel.getPreferencesFromUser方法的典型用法代码示例。如果您正苦于以下问题:Java DataModel.getPreferencesFromUser方法的具体用法?Java DataModel.getPreferencesFromUser怎么用?Java DataModel.getPreferencesFromUser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mahout.cf.taste.model.DataModel
的用法示例。
在下文中一共展示了DataModel.getPreferencesFromUser方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runALSSVDRecommender
import org.apache.mahout.cf.taste.model.DataModel; //导入方法依赖的package包/类
private static void runALSSVDRecommender(DataModel dataModel)
throws TasteException {
System.out.println("Start of Running an ALS SVD Recommendation");
RecommenderBuilder recommenderBuilder = EEGVideoRecommender.buildSVDRecommender();
SVDRecommender recommender = (SVDRecommender) recommenderBuilder
.buildRecommender(dataModel);
RunningAverage runningAverage = new FullRunningAverage();
LongPrimitiveIterator userIDs = dataModel.getUserIDs();
while (userIDs.hasNext()) {
long userID = userIDs.nextLong();
for (Preference pref : dataModel.getPreferencesFromUser(userID)) {
double ratingValue = pref.getValue();
double preferenceEstimate = recommender.estimatePreference(
userID, pref.getItemID());
System.out.println(userID + "," + pref.getItemID() + ","
+ ratingValue);
double errorValue = ratingValue - preferenceEstimate;
runningAverage.addDatum(errorValue * errorValue);
}
}
double rmse = Math.sqrt(runningAverage.getAverage());
System.out.println(rmse);
// Recommender Evaluation -- Average Absolute Difference Evaluator
RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
null, dataModel, 0.9, 1.0);
System.out.println("ALS-based Recommender Average Score is: " + score);
// Recommender Evaluation -- RMS Evaluator
RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
dataModel, 0.9, 1.0);
System.out.println("ALS-based Recommender RMS Score is:" + rmsscore);
// Recommender Evaluation -- IRStats Evaluator
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = irStatsEvaluator.evaluate(recommenderBuilder,
null, dataModel, null, 2,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
System.out.println("Precision Valus is : " + stats.getPrecision());
System.out.println("Recall Value is : " + stats.getRecall());
System.out.println("End of Running an ALS SVD Recommendation");
}