Shubham Tripathi
Shubham Tripathi

Reputation: 21

SlopeOneRecommender not working

I am following the book Apache Mahout Cookbook by piero giacomelli. Now when i download the maven sources using netbeans as IDE, i guess the sources are from mahout version 1.0 and not 0.8 as it showing an error in SlopeOneRecommender import alone. Here is the complete code -

    package com.packtpub.mahout.cookbook.chapter01;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

import org.apache.commons.cli2.OptionException;
import org.apache.mahout.cf.taste.common.TasteException;
import org.apache.mahout.cf.taste.impl.common.LongPrimitiveIterator;
import org.apache.mahout.cf.taste.impl.model.file.FileDataModel;
import org.apache.mahout.cf.taste.impl.recommender.CachingRecommender;
import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender;
import org.apache.mahout.cf.taste.model.DataModel;
import org.apache.mahout.cf.taste.recommender.RecommendedItem;

public class App {



    static final String inputFile = "/home/hadoop/ml-1m/ratings.dat";
    static final String outputFile = "/home/hadoop/ml-1m/ratings.csv";

    public static void main( String[] args ) throws IOException, TasteException, OptionException
    {
        CreateCsvRatingsFile();


        // create data source (model) - from the csv file
        File ratingsFile = new File(outputFile);
        DataModel model = new FileDataModel(ratingsFile);

        // create a simple recommender on our data
        CachingRecommender cachingRecommender = new CachingRecommender(new SlopeOneRecommender(model));

        // for all users
        for (LongPrimitiveIterator it = model.getUserIDs(); it.hasNext();){
            long userId = it.nextLong();

            // get the recommendations for the user
            List<RecommendedItem> recommendations = cachingRecommender.recommend(userId, 10);

            // if empty write something
            if (recommendations.size() == 0){
                System.out.print("User ");
                System.out.print(userId);
                System.out.println(": no recommendations");
            }

            // print the list of recommendations for each
            for (RecommendedItem recommendedItem : recommendations) {
                System.out.print("User ");
                System.out.print(userId);
                System.out.print(": ");
                System.out.println(recommendedItem);
            }
        }
    }

    private static void CreateCsvRatingsFile() throws FileNotFoundException, IOException {

        BufferedReader br = new BufferedReader(new FileReader(inputFile));
        BufferedWriter bw = new BufferedWriter(new FileWriter(outputFile));


        String line = null;
        String line2write = null;
        String[] temp;


        int i = 0;
        while (
                    (line = br.readLine()) != null
                && i < 1000
                ){
            i++;
            temp = line.split("::");
            line2write = temp[0] + "," + temp[1];
            bw.write(line2write);
            bw.newLine();
            bw.flush();

        }
        br.close();
        bw.close();
    }
}

The error is being shown only on import org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender;

and hence on the line where i create an object using this. Error being shown is package does not exist. Please help. Is it because i am using a newer version of mahout? I am even uncertain if I am using version 0.8 or a higher version as i followed all the links given in the book.

Upvotes: 1

Views: 455

Answers (2)

ghiz
ghiz

Reputation: 11

Exactly,
The SlopeOneRecommender was removed from mahout since v0.8. So either you get back to the version 0.7. Or if your purpose is only to try mahout u can try with other recommenders, such as :ItemAverageRecommender.

Upvotes: 1

Joe Cheng
Joe Cheng

Reputation: 9564

The SlopeOneRecommender was removed from mahout since v0.8. If you want to use it, you can switch to version such as 0.7.

<dependency>
    <groupId>org.apache.mahout</groupId>
    <artifactId>mahout-core</artifactId>
    <version>0.7</version>
</dependency>

See http://permalink.gmane.org/gmane.comp.apache.mahout.user/20282

Upvotes: 1

Related Questions