Recommendation for boolean dataset with apache mahout

I was trying to implement Item based Recommender System with the boolean dataset, Dataset example:

      User-id | movie-id | Action | Comedy | Drama
        1              200    0         1        1
        2              210    1         1        0

And I tried implementing it with item-based similarity algorithm as follows:

package prediction.contentrecommender;

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.recommender.GenericItemBasedRecommender; import org.apache.mahout.cf.taste.impl.similarity.TanimotoCoefficientSimilarity; import org.apache.mahout.cf.taste.model.DataModel; import org.apache.mahout.cf.taste.recommender.RecommendedItem; import org.apache.mahout.cf.taste.similarity.ItemSimilarity; import org.apache.mahout.cf.taste.impl.recommender.GenericBooleanPrefItemBasedRecommender;

public class ContentRecommender {

/**
 * @param args
 */
public static void main(String[] args) {
    int userid=10;
       int noOfRecommendations=1;


    try {

        DataModel dm = new FileDataModel(new File("data/dataset.csv"));
        ItemSimilarity sim = new TanimotoCoefficientSimilarity(dm);
        GenericItemBasedRecommender recommender =
            new GenericBooleanPrefItemBasedRecommender(dm,sim);

     ListRecommendedItem recommendations =
         recommender.recommend(userid, noOfRecommendations);
            for(RecommendedItem recommendation : recommendations)
             {
                System.out.println(recommendation.getItemID());
            }


    } 
    catch (IOException e) 
    {
        System.out.println("there is an error");
        e.printStackTrace();
    } 
   catch (TasteException e) 
    {
        System.out.println("error");
        e.printStackTrace();
    }


}

}

When I am running this code, I am not getting any output, although there is no error.I don't know what can be the problem. Can anyone figure out how to implement item-based similarity algorithm with Boolean data-set.

Topic apache-mahout recommender-system machine-learning

Category Data Science


The code and data combination is too small for predicting a solution. But note that you will not get any answer if there are no recommendations made. In this case there will be no exception either. Looks like your code

List<RecommendedItem> recommendations =
     recommender.recommend(userid, noOfRecommendations);

returned no recommendations. You should try with a variety of data.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.