• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java IRStatistics类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.mahout.cf.taste.eval.IRStatistics的典型用法代码示例。如果您正苦于以下问题:Java IRStatistics类的具体用法?Java IRStatistics怎么用?Java IRStatistics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IRStatistics类属于org.apache.mahout.cf.taste.eval包,在下文中一共展示了IRStatistics类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: main

import org.apache.mahout.cf.taste.eval.IRStatistics; //导入依赖的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());
}
 
开发者ID:tensorchen,项目名称:rrs,代码行数:25,代码来源:RecommenderIRStatsEvaluatorTest.java


示例2: runALSSVDRecommender

import org.apache.mahout.cf.taste.eval.IRStatistics; //导入依赖的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");
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:56,代码来源:EEGVideoEvaluator.java


示例3: runUserBasedRecommender

import org.apache.mahout.cf.taste.eval.IRStatistics; //导入依赖的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());

}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:48,代码来源:EEGVideoEvaluator.java


示例4: runItemBasedRecommender

import org.apache.mahout.cf.taste.eval.IRStatistics; //导入依赖的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());

}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:47,代码来源:EEGVideoEvaluator.java


示例5: runUserRecommender

import org.apache.mahout.cf.taste.eval.IRStatistics; //导入依赖的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");
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:74,代码来源:EEGVideoEvaluator.java



注:本文中的org.apache.mahout.cf.taste.eval.IRStatistics类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HttpClient类代码示例发布时间:2022-05-22
下一篇:
Java StreamManagerMBean类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap