我一直在使用此代码,我收到错误
Exception in thread "main" java.util.NoSuchElementException
at com.google.common.base.AbstractIterator.next(AbstractIterator.java:75)
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.processLine(FileDataModel.java:385)
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.processFile(FileDataModel.java:340)
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.buildModel(FileDataModel.java:239)
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.reload(FileDataModel.java:208)
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.<init>(FileDataModel.java:194)
at org.apache.mahout.cf.taste.impl.model.file.FileDataModel.<init>(FileDataModel.java:149)
at ItemRecommender.main(ItemRecommender.java:22)
是否有一些jar文件错误,我需要导入等等...帮助我卡住....代码如下...
import java.io.File;
import java.util.List;
import java.io.IOException;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
import org.apache.mahout.cf.taste.impl.recommender.GenericItemBasedRecommender;
import org.apache.mahout.cf.taste.impl.similarity.LogLikelihoodSimilarity;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;
import org.apache.mahout.cf.taste.similarity.ItemSimilarity;
public class ItemRecommender {
public static void main(String[] args) {
try{
DataModel dm = new FileDataModel(new File("data/movies.csv"));
ItemSimilarity sim = new LogLikelihoodSimilarity(dm);
GenericItemBasedRecommender recommender = new GenericItemBasedRecommender(dm, sim);
int x=1;
for(LongPrimitiveIterator items = dm.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());
}
x++;
//if(x>10) System.exit(1);
}
}catch(IOException e)
{ System.out.println("There was an error.");
e.printStackTrace();
} catch(TasteException e)
{
System.out.println("There was a taste exception.");
e.printStackTrace();
}
} }
答案 0 :(得分:0)
Mahout&#34;品味&#34;框架已被弃用,将很快删除。最好在这里查看项目相似性的新版本:http://mahout.apache.org/users/algorithms/intro-cooccurrence-spark.html
顺便说一下,有一个完全实现的推荐器,其中包含事件摄取和服务层:https://github.com/actionml/template-scala-parallel-universal-recommendation