本文整理汇总了Java中org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator类的典型用法代码示例。如果您正苦于以下问题:Java AverageAbsoluteDifferenceRecommenderEvaluator类的具体用法?Java AverageAbsoluteDifferenceRecommenderEvaluator怎么用?Java AverageAbsoluteDifferenceRecommenderEvaluator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AverageAbsoluteDifferenceRecommenderEvaluator类属于org.apache.mahout.cf.taste.impl.eval包,在下文中一共展示了AverageAbsoluteDifferenceRecommenderEvaluator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: evaluateRecommender
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的package包/类
public static void evaluateRecommender() throws Exception{
StringItemIdFileDataModel dataModel = loadFromFile("data/BX-Book-Ratings.csv",";");
RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
RecommenderBuilder builder = new BookRecommender();
double result = evaluator.evaluate(builder, null, dataModel, 0.9, 1.0);
System.out.println(result);
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:8,代码来源:BookRecommender.java
示例2: main
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的package包/类
public static void main(String[] args) throws IOException, TasteException {
RandomUtils.useTestSeed();
final DataModel model = new FileDataModel(new File("data/ua.base"));
RecommenderEvaluator evaluator = new AverageAbsoluteDifferenceRecommenderEvaluator();
RecommenderBuilder builder = 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);
}
};
double score = evaluator.evaluate(builder, null, model, 0.7, 1.0);
System.out.println(score);
}
示例3: evaluate
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的package包/类
public static void evaluate(String ratingsFile)
throws TasteException, IOException {
DataModel model = new FileDataModel(new File(ratingsFile));
RecommenderEvaluator evaluator =
new AverageAbsoluteDifferenceRecommenderEvaluator();
RecommenderBuilder recommenderBuilder = new MyRecommendBuilder();
evaluator.evaluate(
recommenderBuilder,
null,
model,
0.95,
0.05
);
}
示例4: buildEvaluator
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的package包/类
public static RecommenderEvaluator buildEvaluator(EVALUATOR type) {
switch (type) {
case RMS:
return new RMSRecommenderEvaluator();
case AVERAGE_ABSOLUTE_DIFFERENCE:
default:
return new AverageAbsoluteDifferenceRecommenderEvaluator();
}
}
示例5: analyze
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的package包/类
/**
* <b>[推薦の評価方法]</b><br>
* cf.)70%のデータを使用してレコメンダーを生成→30%のデータを使用して評価
* @param dataModel
* @throws TasteException
*/
@Override
public void analyze() throws TasteException {
super.i("◆ EVAL ======= Start ======");
super.i("◆ -------------------------");
final int size = super.dto.size;
final Map<EvalName, EvaluationVO> evalMap = super.dto.evalMap;
RandomUtils.useTestSeed();
/* 実際の評価値と推定値の誤差 */
// 絶対値を求める=意味平均誤差(mean average error)
RecommenderEvaluator maeEval = new AverageAbsoluteDifferenceRecommenderEvaluator();
// 自乗を足し合わせ平方根を取ったRMS(root mean squared)
RecommenderEvaluator rmsEval = new RMSRecommenderEvaluator();
RecommenderBuilder builder = new RecommenderBuilder() {
@Override
public Recommender buildRecommender(DataModel dataModel) throws TasteException {
UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel);
UserNeighborhood neighborhood = new NearestNUserNeighborhood(size, similarity, dataModel);
return new GenericUserBasedRecommender(dataModel, neighborhood, similarity);
}
};
// evaluate(RecommenderBuilder, DataModelBuilder, DataModel, 学習用データの割合, 検証用データの割合)
EvaluationVO mae = evalMap.get(EvalName.MAE);
EvaluationVO rms = evalMap.get(EvalName.RMS);
double maeScore = maeEval.evaluate(builder, null, super.dataModel, mae.trainingPercentage, mae.evaluationPercentage);
double rmsScore = rmsEval.evaluate(builder, null, super.dataModel, rms.trainingPercentage, rms.evaluationPercentage);
super.i("◆ " + EvalName.MAE.name + " : " + maeScore);
super.i("◆ " + EvalName.RMS.name + " : " + rmsScore);
super.i("◆ -------------------------");
super.iln("◆ EVAL ======= END ======");
}
示例6: runALSSVDRecommender
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的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");
}
示例7: runUserBasedRecommender
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的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());
}
示例8: runItemBasedRecommender
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的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());
}
示例9: runUserRecommender
import org.apache.mahout.cf.taste.impl.eval.AverageAbsoluteDifferenceRecommenderEvaluator; //导入依赖的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");
}