Mahout Development Environment with Maven and Eclipse (2)

Sample Codes of “Mahout in Action”

The sample codes of “Mahout in Action”, which is a Mahout book from Manning, are published at here. They include source codes in Chapter 2 to 6.

Now, We’ll build them on the Eclipse environment constructec in the previous post.

At first, generate a Maven project for sample codes on the Eclipse workspace directory.

$ cd C:/Users/shuyo/workspace
$ mvn archetype:create -DgroupId=mia.recommender -DartifactId=recommender

Do the following.

  • Delete a generated skelton code src/main/App.java and copy the sample code of “Mahout in Action” into src/main/java/mia/recommender/ch02 ~ ch06 of the ‘recommender’ project.
  • Convert the Maven project into Eclipse project.
    $ cd C:/Users/shuyo/workspace/recommender
    $ mvn eclipse:eclipse
    
  • Import the project into Eclipse.
    Open File > Import > General > Existing Projects into Workspace from Eclipse menu and select the ‘recommender’ project.
  • Then the ‘recommender’ project is available on Eclipse workspace, but all classes have errors because of no Mahout library reference.

    Right click the ‘recommender’ project, select Properties > Java Build Path > Projects from pop-up menu and click ‘Add’ and select the below Mahout projects.

    • mahout-core
    • mahout-examples
    • mahout-taste-webapp

    Then only 4 errors remain.

    Hence they are conflicts with updated APIs, these error correction need to modify codes.
    For example, open mia.recommender.ch03.IREvaluatorBooleanPrefIntro2 and press ctrl+1 at error line in it.

    This error says that the code does not catch or declare a exception of TasteException which NearestNUserNeighborhood’s constructor throws. So you can choise whichever you like a solution in the pop up menu. Others as well.

    The classes which has main() function can be executed on Eclipse.
    For example, select mia.recommender.ch02.RecommenderIntro and click Run > Run in Eclipse’s menu (or may press ctrl+F11 insted). Then It throws an exception as ‘Exception in thread “main” java.io.FileNotFoundException: intro.csv’.
    To make it read a sample data file ‘intro.csv’ in src/mia/recommender/ch02, click Run > Run Configurations in Eclipse’s menu and select the configuration of RecommenderIntro which is created by the above execution. Then set mia/recommender/ch02 to Working directory in Arguments tab(see the below figure). Click “Workspace…” button and select the directory.

    Then it outputs a result like “RecommendedItem[item:104, value:4.257081]”.
    If you want to make a project, repeat from Maven project creation.

    Advertisements
This entry was posted in Eclipse, Java, Machine Learning, Mahout, Maven. Bookmark the permalink.

27 Responses to Mahout Development Environment with Maven and Eclipse (2)

  1. Thank you for writing this up! It was very useful in getting set up with a new Mahout project in Eclipse.

  2. mak says:

    Thanks. Neat.

  3. anupsavvy says:

    Thanks man!!! It helps. I appreciate it.

  4. j.c. says:

    I am getting the following error when I try to create eclipse project. Any idea on how to fix it?

    Unable to find resource ‘org.apache.mahout:mahout-eclipse-support:pom:1.0-SNAPSHOT’ in repository apache.snapshots (http://repository.apache.org/snapshots)

    Thanks,

  5. shuyo says:

    I have no idea about your trouble…
    How about instaling all cleanly?

  6. 么昌龙(yao changlong) says:

    Thanks you very much!It cant be more helpfull!

  7. Michael says:

    Thank you very much: indeed very helpful!

  8. kostas says:

    why install cygwin? is it possible to do without?

  9. Ali says:

    I have a problem in project mahout-taste-webapp, it’s impossible to deploy it.
    please you can send me à good link to download Mahout project

    thank you for your help and your tutorial.

    the error :
    INFO] Scanning for projects…
    INFO]
    INFO] ————————————————————————
    INFO] Building Mahout Taste Webapp 0.5
    INFO] ————————————————————————
    INFO]
    INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ mahout-taste-webapp >>>
    INFO]
    INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ mahout-taste-webapp << [Help 1]
    ERROR]
    ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    ERROR] Re-run Maven using the -X switch to enable full debug logging.
    ERROR]
    ERROR] For more information about the errors and possible solutions, please read the following articles:
    ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

  10. Laila M. says:

    Thanks alot, it’s very useful…
    I just faced one problem in this command

    cd C:/Users/shuyo/workspace
    $ mvn archetype:create -DgroupId=mia.recommender -DartifactId=recommender

    it made an error because the create command is changed into generate.
    $ mvn archetype:generate -DgroupId=mia.recommender -DartifactId=recommender

    when I exchange it, it worked well 🙂 .. I just want to ask what shall I do next, I didn’t figure out what is the mahout classes and how to write my own code.. shall I read the book you mentioned “Mahout in action”.

    I’ll be grateful to give me an advice.. as I want to compare between the Recommender System tools so I have be familiar with its functionality and features.

    Thanks again for ur great affort 🙂

    • shuyo says:

      Sorry for my late response.

      > it made an error because the create command is changed into generate.

      Mmh, I see. The create goal had been deprecated(I didn’t know…).
      The following is probably equal to the original create version.

      $ mvn archetype:generate -DgroupId=mia -DartifactId=recommender -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false

      After this, it is OK as the above article (perhaps…)

  11. Eli Finkelshteyn says:

    It seems the source for the chapters mentioned here may have changed since this was posted. Because of that, I needed to make a number of changes to get things working error-free.

    1. You must add the mahout-math library in addition to mahout-core, mahout-examples, etc…
    2. Various parts of the code ask for Hadoop-related functions (i.e. AggregateAndRecommendReducer.java asking for org.apache.hadoop.conf.Configuration). In order to satisfy these, you must add the Hadoop library as well. Shuyo has a pretty good tutorial of this as well if you search for “hadoop-development-environment-with-eclipse”

    • shuyo says:

      Thanks for your information.
      As yo mentioned, I’m afraid this article might be old.
      But I have no plan to the newest version of mahout now…

  12. Eli Finkelshteyn says:

    Woops. that last comment was completely wrong on #2. Just add the hadoop-core jar file to referenced libraries instead. Much easier.

  13. thanks ,it’s very useful

  14. news says:

    Although I actually like this post, I think there was an punctuational error shut towards the end with the 3rd paragraph.

  15. ROOTKIM says:

    Really thank you for posting.
    I’ve been in the trouble setting in eclipse and now I’m clear for your detail post!

  16. Just for information – I wrote a post on how to use Mahout in Action’s examples with Eclipse: http://alexott.blogspot.de/2012/07/getting-started-with-examples-from.html

  17. spid says:

    while adding java build paths mahout-taste-webapp is not there.
    so please tell me how to get this
    though it worked fine and i got the result u showed it is also giving some errors…

  18. Martha says:

    I was struggling for days trying to import mahout as a maven project with numerous errors. Thanks for providing clear step-by-step instructions – it really helped!!! (I had to make minor tweaks due to different version and OS – e.g. taste is now included in the mahout core in version .7)

  19. sergio gomez says:

    me puedes ayudar a correr el ultimo ejemplo

  20. Rave says:

    Great helps a lot for beginners

  21. nom says:

    OK. Now what:

    Delete a generated skelton code src/main/App.java and copy the sample code of “Mahout in Action” into src/main/java/mia/recommender/ch02 ~ ch06 of the ‘recommender’ project.

    What are you talking about here?

    What kind of “generated skelton code”? What is this? Where do I find it?
    And where do I get the sample code of Mahout in Action? Do I have to buy the book? And where in the recommender project do I have to paste the sample code?

    Thanks in advance.

  22. Excellent, what a website it is! This website provides useful
    data to us, keep it up.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s