Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Precision and NDCG are NaN #248

Closed
abdollahpouri opened this issue Mar 28, 2018 · 1 comment
Closed

Precision and NDCG are NaN #248

abdollahpouri opened this issue Mar 28, 2018 · 1 comment
Labels

Comments

@abdollahpouri
Copy link

Hello,
I am trying to use the code snippet you provided in your Github page to run the recommendation algorithm in my program. Here is my code:

public class MyRecommender {
    public static String CONFIG_FILE =
            "conf/librec.properties";

    public static void main(String[] args) throws Exception {

        // recommender configuration
        Configuration conf = new Configuration();
        String confFilePath = CONFIG_FILE;
        Properties prop = new Properties();
        prop.load(new FileInputStream(confFilePath));
        for (String name : prop.stringPropertyNames()) {
            conf.set(name, prop.getProperty(name));
        }

        // build data model
        DataModel dataModel = new TextDataModel(conf);
        dataModel.buildDataModel();

        // set recommendation context
        RecommenderContext context = new RecommenderContext(conf, dataModel);
        RecommenderSimilarity similarity = new PCCSimilarity();
        similarity.buildSimilarityMatrix(dataModel);
        context.setSimilarity(similarity);

        // training
        Recommender recommender = new UserKNNRecommender();
        recommender.recommend(context);

        // evaluation
        RecommenderEvaluator maeEvaluator = new MAEEvaluator();
        RecommenderEvaluator precisionEvaluator = new PrecisionEvaluator();
        RecommenderEvaluator normalizedDCGEvaluator = new NormalizedDCGEvaluator();


        double precision=recommender.evaluate(precisionEvaluator);
        //double mae=recommender.evaluate(maeEvaluator);
        double ndcg=recommender.evaluate(normalizedDCGEvaluator);
       // System.out.println("MAE: "+ mae );
        System.out.println("Precision: "+ precision );
        System.out.println("NDCG: "+ ndcg );

        // recommendation results
        List recommendedItemList = recommender.getRecommendedList();
        RecommendedFilter filter = new GenericRecommendedFilter();
        recommendedItemList = filter.filter(recommendedItemList);
    }
}

And here is my librec.properties file:

# set data directory
dfs.data.dir=data
# set result directory
# recommender result will output in this folder
dfs.result.dir=result


data.model.splitter=testset
data.input.path=ml-100k
data.testset.path=ml-100k/u1.test


rec.recommender.isranking=true
rec.recommender.ranking.topn=10



# convertor
# load data and splitting data 
# into two (or three) set
# setting dataset name
# setting dataset format(UIR, UIRT)
data.column.format=UIR
# setting method of split data
# value can be ratio, loocv, given, KCV
#data.splitter.cv.number=5
# using rating to split dataset
data.splitter.ratio=rating
# filmtrust dataset is saved by text
# text, arff is accepted
data.model.format=text
# the ratio of trainset
# this value should in (0,1)
data.splitter.trainset.ratio=0.8

# Detailed configuration of loocv, given, KCV 
# is written in User Guide 

# set the random seed for reproducing the results (split data, init parameters and other methods using random)
# default is set 1l
# if do not set ,just use System.currentTimeMillis() as the seed and could not reproduce the results.
rec.random.seed=1

# binarize threshold mainly used in ranking
# -1.0 - maxRate, binarize rate into -1.0 and 1.0
# binThold = -1.0, do nothing
# binThold = value, rating > value is changed to 1.0 other is 0.0, mainly used in ranking
# for PGM 0.0 maybe a better choose
data.convert.binarize.threshold=-1.0

# evaluation the result or not
rec.eval.enable=true

# specifies evaluators
# rec.eval.classes=auc,precision,recall...
# if rec.eval.class is blank 
# every evaluator will be calculated
# rec.eval.classes=auc,precision,recall

# evaluator value set is written in User Guide
# if this algorithm is ranking only true or false




#can use user,item,social similarity, default value is user, maximum values:user,item,social
#rec.recommender.similarities=user

rec.similarity.class=pcc
rec.neighbors.knn.number=50
rec.recommender.class=userknn
rec.recommender.similarities=user
rec.filter.class=generic
rec.similarity.shrinkage=10

But both precision and ncdg are NaN.

@SunYatong
Copy link
Collaborator

Ranking evaluator requires an additional "topN" configuration.

        // evaluation
        RecommenderEvaluator precisionEvaluator = new PrecisionEvaluator();
        RecommenderEvaluator normalizedDCGEvaluator = new NormalizedDCGEvaluator();
        precisionEvaluator.setTopN(10);
        normalizedDCGEvaluator.setTopN(10);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants