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.
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.