2
votes

I am trying to learn Apache mahout, very new to this topic. I want to implement user-based recommender. For this, after exploring on the internet I have found some samples like below,

public static void main(String[] args) {
        try {
            int userId = 2;

            DataModel model = new FileDataModel(new File("data/mydataset.csv"), ";");
            UserSimilarity similarity = new PearsonCorrelationSimilarity(model);
            UserNeighborhood neighborhood = new NearestNUserNeighborhood(2, similarity, model);
            UserBasedRecommender recommender = new GenericUserBasedRecommender(model, neighborhood, similarity);

            List<RecommendedItem> recommendations = recommender.recommend(userId, 3);
            for (RecommendedItem recommendation : recommendations) {
                logger.log(Level.INFO, "Item Id recommended : " + recommendation.getItemID() + " Ratings : "
                        + recommendation.getValue() + " For UserId : " + userId);
            }
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Exception in main() ::", e);
        }

I am using following dataset which contains userid, itemid, preference value respectively,

1,10,1.0
1,11,2.0
1,12,5.0
1,13,5.0
1,14,5.0
1,15,4.0
1,16,5.0
1,17,1.0
1,18,5.0
2,10,1.0
2,11,2.0
2,15,5.0
2,16,4.5
2,17,1.0
2,18,5.0
3,11,2.5
3,12,4.5
3,13,4.0
3,14,3.0
3,15,3.5
3,16,4.5
3,17,4.0
3,18,5.0
4,10,5.0
4,11,5.0
4,12,5.0
4,13,0.0
4,14,2.0
4,15,3.0
4,16,1.0
4,17,4.0
4,18,1.0

In this case, it works fine, but my main question is I have the different set of data which don't have preference values, which contains some data based on that I am thinking to compute preference values. Following is my new dataset,

userid  itemid  likes   shares  comments
1        4       1      20      3
2        6       18     20      12
3        12      10     2       20
4        7       0      20      13
5        9       0      2       1
6        5       5      3       2
7        3       9      7       0
8        1       15     0       0

My question is how can I compute preference value for a particular record based on some other columns such as likes, shares, comments etc. Is there anyway to compute this in mahout?

2

2 Answers

2
votes

Yes- I think your snippet is from an older version of Mahout, but what you want to use is the Correlated Co Occurrence recommender. The CCO Recommender is multi-modal (allows user to have various inputs).

There are CLI Drivers, but I'm guessing you want to code, there is a Scala tutorial here

In the tutorial I think it recommends 'friends' based on genres tagged and artists 'liked', as well as your current friends.

2
votes

As @rawkintrevo says, Mahout has moved on from the older "taste" recommenders and they will be deprecated from Mahout soon.

You can build you own system from the CCO algorithm in Mahout here. It allows you to use data from different user behavior like "likes, shares, comments". So we call it multi-modal.

Or in another project we have created a full featured recommendation server based on Mahout, called the Universal Recommender. It is build on Apache PredicitonIO where the UR is a plugin called a Template. Together they deliver a nearly turnkey server that takes input and responds to queries. To get started easily try the AWS AMI that has the whole system working. Some other methods to install are shown here.

This is all Apache licensed OSS, but Mahout no longer can really provide a production ready environment, Mahout does algorithms but you need a system around it. Build your own or try the PredictionIO based one. Since everything is OSS you can tweak things if needed.