librec
librec copied to clipboard
TrustMF, dataAppender not working
Hi, I have a problem with the library 3.0.0. I want to use TrustMF in a subset of Yelp dataset. I have tried starting this tutorial but I have problem with DataAppender. This is the main I have used.
public class MainTest {
public static void main(String[] args) throws Exception {
// build data model
Configuration conf = new Configuration();
conf.set("dfs.data.dir", "/home/fily1212/universita/Lavoro_Yelp/librec-3.0.0/data");
conf.set("data.input.path","yelp");
TextDataModel dataModel = new TextDataModel(conf);
dataModel.buildDataModel();
// build recommender context
conf.set("data.appender.class","social");
conf.set("data.appender.path", "yelp/trust");
conf.set("rec.recommender.class","trustmf");
conf.set("rec.iterator.learnrate","0.01");
conf.set("rec.iterator.learnrate.maximum","0.01");
conf.set("rec.iterator.maximum","30");
conf.set("rec.user.regularization","0.01");
conf.set("rec.item.regularization","0.01");
conf.set("rec.social.regularization","0.01");
conf.set("rec.factor.number","10");
conf.set("rec.learnrate.bolddriver","false");
conf.set("rec.learnrate.decay","1.0");
conf.set("rec.recommender.earlystop","false");
conf.set("rec.recommender.verbose","true");
conf.set("rec.social.model","T");
String inputPath = conf.get("dfs.data.dir") + "/" + conf.get("data.input.path");
TextDataConvertor textDataConvertor = new TextDataConvertor(inputPath);
textDataConvertor.processData();
SocialDataAppender dataAppender = new SocialDataAppender(conf);
dataAppender.setUserMappingData(textDataConvertor.getUserIds());
dataAppender.processData();
RecommenderContext context = new RecommenderContext(conf, dataModel);
// build similarity
conf.set("rec.recommender.similarity.key" ,"user");
conf.setBoolean("rec.recommender.isranking", true);
conf.setInt("rec.similarity.shrinkage", 10);
RecommenderSimilarity similarity = new CosineSimilarity();
similarity.buildSimilarityMatrix(dataModel);
context.setSimilarity(similarity);
// build recommender
conf.set("rec.neighbors.knn.number", "200");
Recommender recommender = new TrustMFRecommender();
recommender.setContext(context);
// run recommender algorithm
recommender.train(context);
// evaluate the recommended result
EvalContext evalContext = new EvalContext(conf, recommender, dataModel.getTestDataSet(), context.getSimilarity().getSimilarityMatrix(), context.getSimilarities());
RecommenderEvaluator ndcgEvaluator = new NormalizedDCGEvaluator();
ndcgEvaluator.setTopN(10);
double ndcgValue = ndcgEvaluator.evaluate(evalContext);
System.out.println("ndcg:" + ndcgValue);
}
}
but I have this output:
18/12/19 15:22:31 INFO TextDataConvertor: Dataset: [/home/fily1212/universita/Lavoro_Yelp/librec-3.0.0/data/yelp]
18/12/19 15:22:31 INFO TextDataConvertor: DataSet: ...rec-3.0.0/data/yelp/trust/trust.txt is finished
18/12/19 15:22:31 INFO TextDataConvertor: DataSet: ...c-3.0.0/data/yelp/rating/rating.txt is finished
18/12/19 15:22:31 INFO TextDataConvertor: rating Scale: [1.0, 2.0, 3.0, 4.0, 5.0]
18/12/19 15:22:31 INFO TextDataConvertor: user number: 884, item number is: 1171
18/12/19 15:22:31 INFO TextDataModel: Transform data to Convertor successfully!
18/12/19 15:22:31 INFO TextDataModel: Split data to train Set and test Set successfully!
18/12/19 15:22:31 INFO TextDataModel: Data cardinality of training is 974
18/12/19 15:22:31 INFO TextDataModel: Data cardinality of testing is 228
18/12/19 15:22:31 INFO TextDataConvertor: Dataset: [/home/fily1212/universita/Lavoro_Yelp/librec-3.0.0/data/yelp]
18/12/19 15:22:31 INFO TextDataConvertor: DataSet: ...rec-3.0.0/data/yelp/trust/trust.txt is finished
18/12/19 15:22:31 INFO TextDataConvertor: DataSet: ...c-3.0.0/data/yelp/rating/rating.txt is finished
18/12/19 15:22:31 INFO TextDataConvertor: rating Scale: [1.0, 2.0, 3.0, 4.0, 5.0]
18/12/19 15:22:31 INFO TextDataConvertor: user number: 884, item number is: 1171
Exception in thread "main" java.lang.NullPointerException
at net.librec.data.convertor.appender.SocialDataAppender.readData(SocialDataAppender.java:150)
at net.librec.data.convertor.appender.SocialDataAppender.processData(SocialDataAppender.java:99)
at net.librec.MainTest.main(MainTest.java:53)
Inspecting the part of code which throws the exception (taken from here)
String inputPath = conf.get("dfs.data.dir") + "/" + conf.get("data.input.path");
TextDataConvertor textDataConvertor = new TextDataConvertor(inputPath);
textDataConvertor.processData();
SocialDataAppender dataAppender = new SocialDataAppender(conf);
dataAppender.setUserMappingData(textDataConvertor.getUserIds());
dataAppender.processData();
I have noticed that textDataConvertor.getUserIds()
isn't defined in TextDataConvertor
.
dataAppender
in the previous link is not defined, but I have came to the conclusion that dataFeatrue
in the link was dataAppender
(maybe it was a typo).
Futhermore the userIds
in textDataConvertor
is null and this cause the exception.
How can I fix it and run a basic TrustMF execution?
Thanks a lot.
Filippo
It would be much more convenient to run with the RecommenderJob and configuration file, instead of coding the whole process of reading data, training and evaluating.
Please check the testcase of TrustMF.