1. Build a Java Project project name on Elcipse: mymahout
2. Create the Libs folder and find the Java package under the Mahout 0.9 lib folder
Where log4j.properties can be found under the Hadoop folder.
Put them under the Libs folder.
3. Copy the folder Libs to the Mymahout project
4. Click the Libs folder, right, select Build Path, and bring the file under the Libs folder.
5. Create the class Mahout and write the following code
ImportJava.io.File;Importjava.util.List;ImportOrg.apache.mahout.cf.taste.impl.model.file.*;ImportOrg.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood;ImportOrg.apache.mahout.cf.taste.impl.recommender.GenericUserBasedRecommender;Importorg.apache.mahout.cf.taste.impl.similarity.PearsonCorrelationSimilarity;ImportOrg.apache.mahout.cf.taste.model.DataModel;ImportOrg.apache.mahout.cf.taste.neighborhood.UserNeighborhood;ImportOrg.apache.mahout.cf.taste.recommender.RecommendedItem;ImportOrg.apache.mahout.cf.taste.recommender.Recommender;Importorg.apache.mahout.cf.taste.similarity.UserSimilarity; Public classMahout { Public Static voidMain (string[] args)throwsException {Datamodel model=NewFiledatamodel (NewFile ("/users/jia/desktop/test.txt")); Usersimilarity Similarity=Newpearsoncorrelationsimilarity (model); Userneighborhood Neighborhood=NewNearestnuserneighborhood (2, Similarity,model); Recommender Recommender=NewGenericuserbasedrecommender (model,neighborhood,similarity); List<RecommendedItem> Recommendations =recommender.recommend (1, 2); for(Recommendeditem recommendation:recommendations) {SYSTEM.OUT.PRINTLN (recommendation); } }}
View Code
6. Running Results
The red section suggests that if you run with a Hadoop cluster, the journal file will be written. This is not to run on the cluster, so alert.
Eclipse Configuration Mahout