请查看以下代码。我正在使用movielens 100k数据集。但是推荐者没有返回推荐项目列表,它返回一个空列表。我哪里出错了?
package org.psneog;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;
import org.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.neighborhood.UserNeighborhood;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.recommender.Recommender;
import org.apache.mahout.cf.taste.similarity.UserSimilarity;
public class MyUserBasedRecommender {
public void myrecommend(String filename) throws IOException, TasteException {
System.out.println("BEGIN myrecommend");
DataModel model = new FileDataModel(new File(filename));
System.out.println("MARK1 " + model.getNumItems());
UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
System.out.println("MARK2 " + similarity);
UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, model);
System.out.println("MARK3 " + neighborhood);
Recommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);
System.out.println("MARK4 " + recommender);
List<RecommendedItem> recommendations = recommender.recommend(751, 10);
System.out.println("MARK5 "+ recommendations );
for(RecommendedItem recommendation: recommendations){
System.out.println(recommendation);
System.out.println("MARK6");
}
System.out.println("END myrecommend");
}
public static void main(String[] args) throws IOException, TasteException {
System.out.println("BEGIN");
MyUserBasedRecommender myreco = new MyUserBasedRecommender();
myreco.myrecommend("ml-100k/u.csv");
System.out.println("END");
}
}
它在MARK5显示一个空列表:
BEGIN
BEGIN myrecommend
MARK1 997
MARK2 PearsonCorrelationSimilarity[dataModel:FileDataModel[dataFile:C:\Users\Prabhakar\workspace_reco\MahoutEvaluation\ml-100k\u.csv],inferrer:null]
MARK3 NearestNUserNeighborhood
MARK4 GenericUserBasedRecommender[neighborhood:NearestNUserNeighborhood]
MARK5 []
END myrecommend
END
请帮帮我