public static void main(String[] args) throws Exception {
File modelFile = null;
if (args.length > 0)
modelFile = new File(args[0]);
if(modelFile == null || !modelFile.exists())
modelFile = new File("intro.csv");加载文件
if(!modelFile.exists()) {
System.err.println("Please, specify name of file, or put file ‘input.csv‘ into current directory!");
System.exit(1);
}
DataModel model = new FileDataModel(modelFile);
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
UserNeighborhood neighborhood =
new NearestNUserNeighborhood(2, similarity, model);
Recommender recommender = new GenericUserBasedRecommender(
model, neighborhood, similarity);
List<RecommendedItem> recommendations =
recommender.recommend(1, 1);推荐,对于用户1 推荐一个
for (RecommendedItem recommendation : recommendations) {
System.out.println(recommendation);
}
}
原文:http://www.cnblogs.com/mrcharles/p/5051850.html