基于java的基于mahout的项目间相似度协同过滤算法

z9smfwbn  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(569)

我一直在使用这个代码,但我得到一个错误

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();
}

} }

qij5mzcb

qij5mzcb1#

mahout“taste”框架正在被弃用,并将很快被删除。最好在这里看一下新版本的item similarity:http://mahout.apache.org/users/algorithms/intro-cooccurrence-spark.html
顺便说一句,这里有一个完全实现的带有事件摄取和服务层的推荐程序:https://github.com/actionml/template-scala-parallel-universal-recommendation

相关问题