本文整理汇总了Java中org.apache.mahout.cf.taste.neighborhood.UserNeighborhood类的典型用法代码示例。如果您正苦于以下问题:Java UserNeighborhood类的具体用法?Java UserNeighborhood怎么用?Java UserNeighborhood使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserNeighborhood类属于org.apache.mahout.cf.taste.neighborhood包,在下文中一共展示了UserNeighborhood类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildRecommend
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public void buildRecommend(String taskName) {
String itemmodelsPath = RecommendConfig.class.getResource("/").getPath() + "itemmodels.csv";
HadoopUtil.download(taskName, itemmodelsPath, true);
try {
DataModel dataModel = new FileDataModel(new File(itemmodelsPath));
UserSimilarity similarity = new SpearmanCorrelationSimilarity(dataModel);
UserNeighborhood userNeighborhood = new ThresholdUserNeighborhood(0.1, similarity, dataModel);
LongPrimitiveIterator userIDs = dataModel.getUserIDs();
while (userIDs.hasNext()) {
Long userID = userIDs.nextLong();
long[] neighborhoods = userNeighborhood.getUserNeighborhood(userID);
for (long neighborhood : neighborhoods) {
double userSimilarity = similarity.userSimilarity(userID, neighborhood);
System.out.printf("(%s,%s,%f)", userID, neighborhood, userSimilarity);
System.out.println();
}
}
} catch (TasteException | IOException e) {
log.error(e);
}
}
开发者ID:babymm,项目名称:mmsns,代码行数:22,代码来源:MahoutRecommender.java
示例2: IRState
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的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();
}
}
开发者ID:babymm,项目名称:mmsns,代码行数:26,代码来源:MahoutRecommender.java
示例3: main
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public static void main(String[] args) throws IOException, TasteException {
DataModel model =
new FileDataModel(new File("data/ua.base"));
UserSimilarity similarity =
new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(2, similarity, model);
Recommender recommender = new GenericUserBasedRecommender(
model, neighborhood, similarity);
List<RecommendedItem> recommendations = recommender.recommend(2, 1);
for (RecommendedItem recommendation : recommendations) {
logger.info(recommendation.toString());
}
logger.info("over");
}
开发者ID:tensorchen,项目名称:rrs,代码行数:22,代码来源:RecommenderIntro.java
示例4: recommend
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
private static void recommend(String ratingsFile, int ... userIds)
throws TasteException, IOException {
DataModel model = new FileDataModel(new File(ratingsFile));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(
100, similarity, model);
Recommender recommender = new GenericUserBasedRecommender(
model, neighborhood, similarity);
Recommender cachingRecommender = new CachingRecommender(recommender);
for(int userId: userIds) {
System.out.println("UserID " + userId);
List<RecommendedItem> recommendations =
cachingRecommender.recommend(userId, 2);
for(RecommendedItem item: recommendations) {
System.out.println(" item " + item.getItemID() + " score " + item.getValue());
}
}
}
开发者ID:Hanmourang,项目名称:hiped2,代码行数:25,代码来源:MovieUserRecommender.java
示例5: main
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的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
示例6: main
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public static void main(String[] args) {
try {
MysqlDataSource dataSource = new MysqlDataSource();
dataSource.setServerName("localhost");
dataSource.setUser("root");
dataSource.setPassword("root");
dataSource.setDatabaseName("rec");
JDBCDataModel dm = new MySQLJDBCDataModel(dataSource,"ratings","userid","itemid","rating","");
UserSimilarity similarity = new PearsonCorrelationSimilarity(dm);
UserNeighborhood neighbor = new NearestNUserNeighborhood(2,similarity, dm);
Recommender recommender = new GenericUserBasedRecommender(dm, neighbor, similarity);
List<RecommendedItem> list = recommender.recommend(1, 3);// recommend
// one item
// to user
// 1
for (RecommendedItem ri : list) {
System.out.println(ri);
}
} catch (Exception e) {
e.printStackTrace();
}
}
开发者ID:laozhaokun,项目名称:movie_recommender,代码行数:24,代码来源:RecommenderWithMahout.java
示例7: main
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public static void main( String[] args ) throws IOException, TasteException
{
//user based recommender model
DataModel model = new FileDataModel(new File("data/dataset.csv"));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
List<RecommendedItem> recommendations = recommender.recommend(2, 3);
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
开发者ID:PacktPublishing,项目名称:Building-Recommendation-Engines,代码行数:13,代码来源:UserbasedRecommender.java
示例8: getSimilarStudents
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
@Override
public List<Student> getSimilarStudents(Student student) {
UserNeighborhood userNeighborhood = studentNeighborhoodStore.getStudentNeighborhood();
long[] userIds;
try {
userIds = userNeighborhood.getUserNeighborhood(student.getId());
} catch (TasteException e) {
return Collections.emptyList();
}
ArrayList<Student> students = new ArrayList<>();
Arrays.stream(userIds).forEach(id -> students.add(studentRepository.findOne(id)));
return students;
}
开发者ID:university-information-system,项目名称:uis,代码行数:16,代码来源:StudentSimilarityServiceImpl.java
示例9: getStudentNeighborhood
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
@Override
@Cacheable(STUDENT_NEIGHBORHOOD_CACHE_NAME)
public UserNeighborhood getStudentNeighborhood() {
DataModel model = buildDataModel();
UserSimilarity similarity = buildSimilarityIndex(model);
return new ThresholdUserNeighborhood(0.3, similarity, model);
}
开发者ID:university-information-system,项目名称:uis,代码行数:9,代码来源:StudentNeighborhoodStoreImpl.java
示例10: main
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的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);
}
开发者ID:tensorchen,项目名称:rrs,代码行数:22,代码来源:RecommenderEvaluatorTest.java
示例11: mahoutSlopeoneGeneratorTest_testBoolRecommender
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的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
示例12: buildRecommender
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
@Override
public UserBasedRecommender buildRecommender(DataModel dataModel) throws TasteException {
UserNeighborhood neighborhood =
new ThresholdUserNeighborhood(
0.1, new PearsonCorrelationSimilarity(dataModel), dataModel);
return new GenericBooleanPrefUserBasedRecommender(
dataModel,
neighborhood,
similarity);
}
开发者ID:balarj,项目名称:rmend-be,代码行数:13,代码来源:CFRecommender.java
示例13: buildRecommender
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
@Override
public Recommender buildRecommender(DataModel model)
throws TasteException {
UserSimilarity similarity =
new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(
100,
similarity, model);
return new GenericUserBasedRecommender(
model, neighborhood, similarity);
}
开发者ID:Hanmourang,项目名称:hiped2,代码行数:15,代码来源:MovieUserEvaluator.java
示例14: userNeighborhood
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public static UserNeighborhood userNeighborhood(NEIGHBORHOOD type, UserSimilarity s, DataModel m, double num) throws TasteException {
switch (type) {
case NEAREST:
/**
* 根据数量构建最近的距离
*/
return new NearestNUserNeighborhood((int) num, s, m);
case THRESHOLD:
default:
/**
* 根据百分比去构建
*/
return new ThresholdUserNeighborhood(num, s, m);
}
}
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:16,代码来源:RecommendFactory.java
示例15: userCF
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public static void userCF(DataModel dataModel) throws TasteException {
UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.CITYBLOCK, dataModel);
UserNeighborhood userNeighborhood = RecommendFactory.userNeighborhood(RecommendFactory.NEIGHBORHOOD.NEAREST, userSimilarity, dataModel, NEIGHBORHOOD_NUM);
RecommenderBuilder recommenderBuilder = RecommendFactory.userRecommender(userSimilarity, userNeighborhood, true);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
LongPrimitiveIterator iter = dataModel.getUserIDs();
while (iter.hasNext()) {
long uid = iter.nextLong();
List<RecommendedItem> list = recommenderBuilder.buildRecommender(dataModel).recommend(uid, RECOMMENDER_NUM);
RecommendFactory.showItems(uid, list, true);
}
}
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:16,代码来源:RecommenderTest.java
示例16: userLoglikelihood
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
/**
* UserCF1
* 1、首先我们需要传递数据模型,然后去构建用户的相似度
* 2、找到用户的近邻
* 3、构建推荐的Builder
* 4、对结果进行评分
* [其他的基本上也是一样]
*/
public static RecommenderBuilder userLoglikelihood(DataModel dataModel) throws TasteException, IOException {
System.out.println("userLoglikelihood");
UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.LOGLIKELIHOOD, dataModel);
UserNeighborhood userNeighborhood = RecommendFactory.userNeighborhood(RecommendFactory.NEIGHBORHOOD.NEAREST, userSimilarity, dataModel, NEIGHBORHOOD_NUM);
RecommenderBuilder recommenderBuilder = RecommendFactory.userRecommender(userSimilarity, userNeighborhood, false);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
return recommenderBuilder;
}
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:19,代码来源:RecommenderEvaluator.java
示例17: userCityBlock
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
/**
* Recommender IR Evaluator: [Precision:0.919580419580419,Recall:0.4371584699453552]
*/
public static RecommenderBuilder userCityBlock(DataModel dataModel) throws TasteException, IOException {
System.out.println("userCityBlock");
UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.CITYBLOCK, dataModel);
UserNeighborhood userNeighborhood = RecommendFactory.userNeighborhood(RecommendFactory.NEIGHBORHOOD.NEAREST, userSimilarity, dataModel, NEIGHBORHOOD_NUM);
RecommenderBuilder recommenderBuilder = RecommendFactory.userRecommender(userSimilarity, userNeighborhood, false);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
return recommenderBuilder;
}
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:14,代码来源:RecommenderEvaluator.java
示例18: userTanimoto
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
public static RecommenderBuilder userTanimoto(DataModel dataModel) throws TasteException, IOException {
System.out.println("userTanimoto");
UserSimilarity userSimilarity = RecommendFactory.userSimilarity(RecommendFactory.SIMILARITY.TANIMOTO, dataModel);
UserNeighborhood userNeighborhood = RecommendFactory.userNeighborhood(RecommendFactory.NEIGHBORHOOD.NEAREST, userSimilarity, dataModel, NEIGHBORHOOD_NUM);
RecommenderBuilder recommenderBuilder = RecommendFactory.userRecommender(userSimilarity, userNeighborhood, false);
RecommendFactory.evaluate(RecommendFactory.EVALUATOR.AVERAGE_ABSOLUTE_DIFFERENCE, recommenderBuilder, null, dataModel, 0.7);
RecommendFactory.statsEvaluator(recommenderBuilder, null, dataModel, 2);
return recommenderBuilder;
}
开发者ID:Hope6537,项目名称:hope-tactical-equipment,代码行数:11,代码来源:RecommenderEvaluator.java
示例19: getNeighborhood
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
/**
* Get the user neighborhood instance, with the correct neighborhood size and algorithm
* as specified during the construction of this RecommendEntityServlet.
* @param similarity The similarity to form the neighborhood
* @param model The database model to get the neighborhood of
* @return The UserNeighborhood instance
* @throws Exception If an exception is thrown by Mahout it is forwarded upwards.
*/
private UserNeighborhood getNeighborhood(UserSimilarity similarity, DataModel model) throws TasteException {
if(this.neighborhoodAlg.equalsIgnoreCase(N_THRESHOLD)){
return new ThresholdUserNeighborhood(this.neighborhoodSize, similarity, model);
} else if(this.neighborhoodAlg.equalsIgnoreCase(N_NUSER) || this.neighborhoodAlg == null){ // == null is the default case
return new NearestNUserNeighborhood((int)this.neighborhoodSize, similarity, model);
} else {
throw new TasteException("Unknown neighborhood algorithm type: " + this.neighborhoodAlg);
}
}
开发者ID:webdsl,项目名称:webdsl,代码行数:18,代码来源:RecommendEntityServlet.java
示例20: recommend
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood; //导入依赖的package包/类
/**
* レコメンデーションを生成して出力
* @param datamodel
* @param similarity
* @param userId
* @param howMany
* @throws TasteException
*/
private void recommend(DataModel datamodel, UserSimilarity similarity, UserAffinityVO dto) throws TasteException {
super.i("◆ " + similarity.getClass());
similarity.setPreferenceInferrer(new AveragingPreferenceInferrer(datamodel));
UserNeighborhood neighbor = new NearestNUserNeighborhood(dto.size, similarity, datamodel);
Recommender recommender = new GenericUserBasedRecommender(datamodel, neighbor, similarity);
List<RecommendedItem> items = recommender.recommend(dto.userId, dto.howMany);
for (RecommendedItem item : items) {
super.i("◆ " + item);
}
}
开发者ID:pollseed,项目名称:machine-learning,代码行数:19,代码来源:User.java
注:本文中的org.apache.mahout.cf.taste.neighborhood.UserNeighborhood类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论