Theoratically there are only two steps to this (well, three if you count the
cd).
Clone GitHub repository available here.
1 |
git clone https://github.com/manthanhd/apache-mahout-recommendation-starter.git |
Change to that directory using cd. Assuming you have gradle installed, run:
1 |
gradle clean run |
You should see output like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
11:47:58: Executing external tasks 'clean run'... :clean :compileJava :processResources :classes log4j:WARN No appenders could be found for logger (org.apache.mahout.cf.taste.impl.model.file.FileDataModel). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info. :run RecommendedItem[item:12, value:4.8328104] RecommendedItem[item:13, value:4.6656213] RecommendedItem[item:14, value:4.331242] BUILD SUCCESSFUL Total time: 0.52 secs 11:47:58: External tasks execution finished 'clean run'. |
The highlighted lines are the recommendations that have been generated. The training data set for this can be found in src/main/resources/dataset.csv file. You can also find it here.
From those highlighted lines, the item:12, item:13 and item:14 refer to the ItemId (second column in data set) and value:4.83, value:4.66 and value:4.33 refer to the recommendation strength. This range depends on the implementation.
1 2 3 4 |
public static void main(String[] args) throws TasteException { Starter starter = new Starter(); starter.recommendFor(2, 3); } |
Looking at the code in Starter.java file, the recommendation is made for UserId (first column in data set) 2. By providing 3 as the second argument we’re asking for 3 item recommendations for this user.
Well, so now that you have the basic framework in place, feel free to play with the UserId values for recommendation, recommendation sizes or even with the data set itself. The more training data you add to the data set, the more accurate its recommendations will be.