本文整理汇总了Java中org.apache.mahout.cf.taste.impl.model.file.FileDataModel类的典型用法代码示例。如果您正苦于以下问题:Java FileDataModel类的具体用法?Java FileDataModel怎么用?Java FileDataModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileDataModel类属于org.apache.mahout.cf.taste.impl.model.file包,在下文中一共展示了FileDataModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildRecommend
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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);
}
}
示例2: IRState
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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();
}
}
示例3: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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");
}
示例4: recommend
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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());
}
}
}
示例5: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
DataModel model = new FileDataModel(new File("data/dataset.csv"));
ItemSimilarity similarity = new LogLikelihoodSimilarity(model);
//UserNeighborhood neighborhood = new ThresholdUserNeighborhood(0.1, similarity, model);
GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(model, similarity);
List<RecommendedItem> recommendations = recommender.mostSimilarItems(18, 3);
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
示例6: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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());
}
示例7: generate
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
private void generate() throws IOException, TasteException {
final DataModel dataModel = new FileDataModel(FileUtils.getFile(this.getFile()));
EvalItemVO evalItemVO = new EvalItemVO(2);
evalItemVO.evalMap.put(EvalName.MAE, new EvaluationVO(0.7, 1.0));
evalItemVO.evalMap.put(EvalName.RMS, new EvaluationVO(0.7, 1.0));
AbstractAnalyzer eval = new Evaluator(dataModel, evalItemVO);
eval.analyze();
UserItemVO userItemVO = new UserItemVO();
userItemVO.userMap.put(UserName.PEARSON, new UserAffinityVO(2, 6, 1));
userItemVO.userMap.put(UserName.EUCLIDEAN, new UserAffinityVO(2, 6, 1));
userItemVO.userMap.put(UserName.COSINE, new UserAffinityVO(2, 6, 1));
AbstractAnalyzer user = new User(dataModel, userItemVO);
user.analyze();
ItemVO itemVO = new ItemVO();
itemVO.itemMap.put(ItemName.TANIMOTO, new ItemAffinityVO(1, 5));
itemVO.itemMap.put(ItemName.CITY_BLOCK, new ItemAffinityVO(1, 5));
itemVO.itemMap.put(ItemName.LOG_LIKE, new ItemAffinityVO(1, 5));
itemVO.itemMap.put(ItemName.EUCLIDEAN, new ItemAffinityVO(1, 5));
itemVO.itemMap.put(ItemName.COSINE, new ItemAffinityVO(1, 5));
AbstractAnalyzer item = new Item(dataModel, itemVO);
item.analyze();
}
示例8: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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);
}
}
示例9: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
public static void main(String[] args) throws TasteException, IOException {
//MF recommender model
DataModel model = new FileDataModel(new File("data/recodataset.csv"));
//ALSWRFactorizer factorizer = new ALSWRFactorizer(model, 50, 0.065, 15);
ParallelSGDFactorizer factorizer = new ParallelSGDFactorizer(model,10,0.1,1);
SVDRecommender recommender = new SVDRecommender(model, factorizer);
List<RecommendedItem> recommendations = recommender.recommend(2, 3);
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
开发者ID:PacktPublishing,项目名称:Building-Recommendation-Engines,代码行数:14,代码来源:UserBasedSVDRecommender.java
示例10: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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);
}
示例11: evaluate
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的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
);
}
示例12: main
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
public static void main( String[] args ) throws IOException, TasteException, OptionException
{
CreateCsvRatingsFile();
// create data source (model) - from the csv file
File ratingsFile = new File(outputFile);
DataModel model = new FileDataModel(ratingsFile);
// create a simple recommender on our data
CachingRecommender cachingRecommender = new CachingRecommender(new SlopeOneRecommender(model));
// for all users
for (LongPrimitiveIterator it = model.getUserIDs(); it.hasNext();){
long userId = it.nextLong();
// get the recommendations for the user
List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 10);
// if empty write something
if (recommendations.size() == 0){
System.out.print("User ");
System.out.print(userId);
System.out.println(": no recommendations");
}
// print the list of recommendations for each
for (RecommendedItem recommendedItem : recommendations) {
System.out.print("User ");
System.out.print(userId);
System.out.print(": ");
System.out.println(recommendedItem);
}
}
}
示例13: recommend
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
public List<RecommendedItem> recommend(int userid,int size) throws TasteException, IOException{
List<RecommendedItem> list = null;
// MovieDataModel model = new MovieDataModel();
String file=ServletActionContext.getServletContext().getRealPath("/u1.base");
DataModel model = new FileDataModel(new File(file));
Recommender recommender = new CachingRecommender(new SlopeOneRecommender(model));
list = recommender.recommend(userid, size);
return list;
}
示例14: recommend
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
public List<RecommendedItem> recommend(int userid,int size) throws TasteException, IOException{
List<RecommendedItem> list = null;
// MovieDataModel model = new MovieDataModel();
String file=ServletActionContext.getServletContext().getRealPath("/u1.base");
DataModel model = new FileDataModel(new File(file));
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood = new NearestNUserNeighborhood(25,similarity, model);
Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
list = recommender.recommend(userid, size);
return list;
}
示例15: recommend
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel; //导入依赖的package包/类
/**
*
* @param userid 当前用户id
* @param size 推荐多少个
* @return 推荐列表
* @throws TasteException
* @throws IOException
*/
public List<RecommendedItem> recommend(int userid,int size) throws TasteException, IOException{
List<RecommendedItem> list = null;
// JDBCDataModel model = new MySQLJDBCDataModel();
String file=ServletActionContext.getServletContext().getRealPath("/u1.base");
DataModel model = new FileDataModel(new File(file));
ItemSimilarity similarity = new PearsonCorrelationSimilarity(model);
Recommender recommender = new GenericItemBasedRecommender(model, similarity);
list = recommender.recommend(userid, size);
return list;
}