当前位置: 首页>>代码示例>>Java>>正文


Java TanimotoCoefficientSimilarity类代码示例

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


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

示例1: mahoutSlopeoneGeneratorTest_testBoolRecommender

import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; //导入依赖的package包/类
@Test
public void mahoutSlopeoneGeneratorTest_testBoolRecommender() throws TasteException {
    EasyrecDataModel easyrecDataModel = new EasyrecDataModel(TENANT_ID, BUY_ACTION_TYPE_ID, false, mahoutDataModelMappingDAO);
    /*TanimotoCoefficientSimilarity is intended for "binary" data sets  where a user either expresses a generic "yes" preference for an item or has no preference.*/
    UserSimilarity userSimilarity = new TanimotoCoefficientSimilarity(easyrecDataModel);

    /*ThresholdUserNeighborhood is preferred in situations where we go in for a  similarity measure between neighbors and not any number*/
    UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1d, userSimilarity, easyrecDataModel);

    /*GenericBooleanPrefUserBasedRecommender is appropriate for use when no notion of preference value exists in the data. */
    Recommender recommender = new GenericBooleanPrefUserBasedRecommender(easyrecDataModel, neighborhood, userSimilarity);

    Assert.assertEquals(30, recommender.recommend(3, 1).get(0).getItemID());
    Assert.assertEquals(1,(int) recommender.recommend(3, 1).get(0).getValue());
}
 
开发者ID:major2015,项目名称:easyrec_major,代码行数:16,代码来源:MahoutBooleanGeneratorTest.java

示例2: getItemSimilarity

import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; //导入依赖的package包/类
@Override
public RecResponseBean getItemSimilarity(long _documentNumber, ResultsType _resultsType)
        throws DatastoreException, DocumentNotFoundException, TasteException {

    SimilarityBuilderWrapper builder =
            new SimilarityBuilderWrapper(
                    new TanimotoCoefficientSimilarity(dataModel));

    List<RecommendedItem> recommendations =
            builder.buildRecommender(dataModel).mostSimilarItems(
                    _documentNumber, _resultsType.getDaoResultLimit());

    Collection<DocumentBean> results = new ArrayList<>(recommendations.size());
    for (RecommendedItem recommendedItem : recommendations) {
        try {
            results.add(dao.getDocument(recommendedItem.getItemID()));
        }
        catch (DocumentNotFoundException e) {
            logger.warn(e);
        }
    }

    // Filter down the result (select randomly from the top results)
    results = ResultsType.getResultsForCF(results, ResultsType.RANDOM_10);
    results = ResultsType.getResultsForCF(results, _resultsType);

    RecResponseBean response = new RecResponseBean(
            results, "CollaborativeFiltering", builder.getSimilarityClass().getSimpleName());

    return response;
}
 
开发者ID:balarj,项目名称:rmend-be,代码行数:32,代码来源:CFRecommender.java

示例3: getSimularity

import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; //导入依赖的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);
    }
}
 
开发者ID:webdsl,项目名称:webdsl,代码行数:25,代码来源:RecommendEntityServlet.java

示例4: analyze

import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; //导入依赖的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 ======");
}
 
开发者ID:pollseed,项目名称:machine-learning,代码行数:50,代码来源:Item.java

示例5: runItemBasedRecommender

import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; //导入依赖的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

示例6: getTanimotoCoefficientSimilarity

import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; //导入依赖的package包/类
public static TanimotoCoefficientSimilarity getTanimotoCoefficientSimilarity(
		DataModel dataModel) throws TasteException {
	System.out.println("TanimotoCoefficientSimilarity");
	return new TanimotoCoefficientSimilarity(dataModel);
}
 
开发者ID:melrefaey,项目名称:EEGoVid,代码行数:6,代码来源:RecommParametersMeasures.java


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