本文整理汇总了Java中org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator类的典型用法代码示例。如果您正苦于以下问题:Java GenericRecommenderIRStatsEvaluator类的具体用法?Java GenericRecommenderIRStatsEvaluator怎么用?Java GenericRecommenderIRStatsEvaluator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GenericRecommenderIRStatsEvaluator类属于org.apache.mahout.cf.taste.impl.eval包,在下文中一共展示了GenericRecommenderIRStatsEvaluator类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IRState
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的package包/类
public void IRState(String taskName) {
String itemmodelsPath = RecommendConfig.class.getResource("/").getPath() + "itemmodels.csv";
HadoopUtil.download(taskName, itemmodelsPath, false);
try {
DataModel fileDataModel = new FileDataModel(new File(itemmodelsPath));
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics irStatistics = irStatsEvaluator.evaluate(new RecommenderBuilder() {
@Override
public org.apache.mahout.cf.taste.recommender.Recommender buildRecommender(final DataModel dataModel) throws TasteException {
UserSimilarity userSimilarity = new PearsonCorrelationSimilarity(dataModel);
UserNeighborhood userNeighborhood = new NearestNUserNeighborhood(5, userSimilarity, dataModel);
return new GenericUserBasedRecommender(dataModel, userNeighborhood, userSimilarity);
}
}, new DataModelBuilder() {
@Override
public DataModel buildDataModel(final FastByIDMap<PreferenceArray> fastByIDMap) {
return new GenericDataModel(fastByIDMap);
}
}, fileDataModel, null, 5, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
System.out.println("查准率:" + irStatistics.getPrecision());
System.out.println("查全率:" + irStatistics.getRecall());
} catch (TasteException | IOException e) {
e.printStackTrace();
}
}
示例2: main
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的package包/类
public static void main(String[] args) throws IOException, TasteException {
RandomUtils.useTestSeed();
final DataModel model = new FileDataModel(new File("data/intro.csv"));
RecommenderIRStatsEvaluator evaluator =
new GenericRecommenderIRStatsEvaluator();
RecommenderBuilder recommenderBuilder = new RecommenderBuilder() {
public Recommender buildRecommender(DataModel dataModel) throws TasteException {
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(2, similarity, model);
return new GenericUserBasedRecommender(model, neighborhood, similarity);
}
};
IRStatistics stats = evaluator.evaluate(recommenderBuilder, null, model, null, 2,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
System.out.println(stats.getPrecision());
System.out.println(stats.getRecall());
}
示例3: statsEvaluator
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的package包/类
/**
* statsEvaluator
*/
public static void statsEvaluator(RecommenderBuilder rb, DataModelBuilder mb, DataModel m, int topn) throws TasteException {
RecommenderIRStatsEvaluator evaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = evaluator.evaluate(rb, mb, m, null, topn, GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1.0);
// System.out.printf("Recommender IR Evaluator: %s\n", stats);
System.out.printf("Recommender IR Evaluator: [Precision:%s,Recall:%s]\n", stats.getPrecision(), stats.getRecall());
}
示例4: runALSSVDRecommender
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的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");
}
示例5: runUserBasedRecommender
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的package包/类
private static void runUserBasedRecommender(DataModel dataModel)
throws TasteException {
UserSimilarity userSimilarity = RecommParametersMeasures
.getLogLikelihoodSimilarity(dataModel);
UserNeighborhood neighborhood = RecommParametersMeasures.getThreshold(
dataModel, userSimilarity, 0.1);
RecommenderBuilder recommenderBuilder = EEGVideoRecommender.userBuilder(
userSimilarity, neighborhood);
for (LongPrimitiveIterator users = dataModel.getUserIDs(); users
.hasNext();) {
long userId = users.nextLong();
List<RecommendedItem> recommendations = recommenderBuilder
.buildRecommender(dataModel).recommend(userId, 1);
for (RecommendedItem recommendation : recommendations) {
System.out.println(userId + "," + recommendation.getItemID()
+ "," + recommendation.getValue());
}
}
// Recommender Evaluation -- Average Absolute Difference Evaluator
RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
null, dataModel, 0.9, 1.0);
System.out.println("User-based Recommender Average Score is: " + score);
// Recommender Evaluation -- RMS Evaluator
RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
dataModel, 0.7, 0.3);
System.out.println("User-based Recommende RMS Score is:" + rmsscore);
// Recommender Evaluation -- IRStats Evaluator
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = irStatsEvaluator.evaluate(recommenderBuilder,
null, dataModel, null, 1,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1);
System.out.println("Precision Valus is : " + stats.getPrecision());
System.out.println("Recall Value is : " + stats.getRecall());
}
示例6: runItemBasedRecommender
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的package包/类
private static void runItemBasedRecommender(DataModel dataModel)
throws TasteException {
TanimotoCoefficientSimilarity tanimotoSimilarity = new TanimotoCoefficientSimilarity(
dataModel);
GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(
dataModel, tanimotoSimilarity);
RecommenderBuilder recommenderBuilder = EEGVideoRecommender
.itemBuilder(tanimotoSimilarity);
for (LongPrimitiveIterator items = dataModel.getItemIDs(); items
.hasNext();) {
long itemId = items.nextLong();
List<RecommendedItem> recommendations = recommender
.mostSimilarItems(itemId, 5);
for (RecommendedItem recommendation : recommendations) {
System.out.println(itemId + "," + recommendation.getItemID()
+ "," + recommendation.getValue());
}
}
// Recommender Evaluation -- Average Absolute Difference Evaluator
RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
null, dataModel, 0.7, 0.3);
System.out.println("Item-based Recommender Average Score is: " + score);
// Recommender Evaluation -- RMS Evaluator
RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
dataModel, 0.7, 0.3);
System.out.println("Item-based Recommende RMS Score is:" + rmsscore);
// Recommender Evaluation -- IRStats Evaluator
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = irStatsEvaluator.evaluate(recommenderBuilder,
null, dataModel, null, 1,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD, 1);
System.out.println("Precision Valus is : " + stats.getPrecision());
System.out.println("Recall Value is : " + stats.getRecall());
}
示例7: runUserRecommender
import org.apache.mahout.cf.taste.impl.eval.GenericRecommenderIRStatsEvaluator; //导入依赖的package包/类
/****************************************** Running Demo for User-based Recommender ******************************************/
private static void runUserRecommender(DataModel dataModel, int n,
double threshold, double training, double evaluation, int atValue,
String similarity) throws TasteException {
System.out.println("Start of Running a User-based Recommender, with:"
+ similarity + " Similarity and training % = " + training
+ " and evaluation % = " + evaluation);
UserSimilarity userSimilarity = null;
UserNeighborhood neighborhood;
if (similarity.equals("pearson")) {
userSimilarity = RecommParametersMeasures
.getPearsonCorrelation(dataModel);
} else if (similarity.equals("likelyhood")) {
userSimilarity = RecommParametersMeasures
.getLogLikelihoodSimilarity(dataModel);
} else if (similarity.equals("tanimoto")) {
userSimilarity = RecommParametersMeasures
.getTanimotoCoefficientSimilarity(dataModel);
} else if (similarity.equals("cityblock")) {
userSimilarity = RecommParametersMeasures
.getCityBlockSimilarity(dataModel);
} else if (similarity.equals("ecludian")) {
userSimilarity = RecommParametersMeasures
.getEuclideanDistance(dataModel);
} else if (similarity.equals("uncenteredcosine")) {
userSimilarity = RecommParametersMeasures.getUncenteredCosine(dataModel);
}
if (n > 0) {
System.out.println("N Size = " + n);
neighborhood = RecommParametersMeasures.getNearestN(dataModel,
userSimilarity, n);
} else {
System.out.println("Threshold value = " + threshold);
neighborhood = RecommParametersMeasures.getThreshold(dataModel,
userSimilarity, threshold);
}
RecommenderBuilder recommenderBuilder = EEGVideoRecommender.userBuilder(
userSimilarity, neighborhood);
recommenderBuilder.buildRecommender(dataModel).recommend(26, 1);
// Recommender Evaluation -- Average Absolute Difference Evaluator
RecommenderEvaluator absoluteDifferenceEvaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
double score = absoluteDifferenceEvaluator.evaluate(recommenderBuilder,
null, dataModel, training, evaluation);
System.out.println("The Average Score for this recommender is: "
+ score);
// Recommender Evaluation -- RMS Evaluator
RecommenderEvaluator rmsEvaluator = new RMSRecommenderEvaluator();
double rmsscore = rmsEvaluator.evaluate(recommenderBuilder, null,
dataModel, training, evaluation);
System.out.println("The RMS Score for Pearson and threshold is:"
+ rmsscore);
// Recommender Evaluation -- IRStats Evaluator
RecommenderIRStatsEvaluator irStatsEvaluator = new GenericRecommenderIRStatsEvaluator();
IRStatistics stats = irStatsEvaluator
.evaluate(recommenderBuilder, null, dataModel, null, 1,
GenericRecommenderIRStatsEvaluator.CHOOSE_THRESHOLD,
evaluation);
System.out.println("The Precision Valus is : " + stats.getPrecision());
System.out.println("The Recall Value is : " + stats.getRecall());
System.out.println("End of Run of user based recommender");
}