Configuration and use of mahout under Eclipse

Source: Internet
Author: User

Mahout is an open source software designed to provide scalability algorithms for real-world problems.

Official homepage: http://mahout.apache.org/

Quickstart:https://cwiki.apache.org/confluence/display/mahout/quickstart

The current version is 0.4, and this example shows how to configure and apply Mahout to your program under Eclipse.

Environment: Eclipse +maven (m2eclipse) + mahout 0.4 +jdk 1.6

Configuration:

Step 1:

Create a new MAVEN program in Eclipse Select "Maven-archetype-quickstart" in "Select an archetype".

Step 2:

Open Pom.xml to add some necessary jars.

Click on the Dependencies tab under Pom.xml and click Add in Dependencies. In the pop-up dialog box, enter "Mahout" to wait a moment will come out a lot of jar package, choose the appropriate mahout package, generally speaking, if you do a very simple program, choose Mahout-core on the line, if you need to distribute computing needs to join Hadoop.

Save Pom.xml This is the program that will automatically download the jar package of your choice.

Instance:

Well, let's use an example to illustrate it:

Create a new class to write the following code:

Import org.apache.mahout.cf.taste.impl.model.file.*; Import org.apache.mahout.cf.taste.impl.neighborhood.*; Import org.apache.mahout.cf.taste.impl.recommender.*; Import org.apache.mahout.cf.taste.impl.similarity.*; Import org.apache.mahout.cf.taste.model.*; Import org.apache.mahout.cf.taste.neighborhood.*; Import org.apache.mahout.cf.taste.recommender.*; Import org.apache.mahout.cf.taste.similarity.*; Import java.io.*; Import java.util.*; public class Recommenderintro {private Recommenderintro () {}, public static void Main (String args[]) throws exception{// STEP:1 Build Model 2 compute similarity 3 find k next to 4 construction recommendation engine Datamodel model =new Filedatamodel (new File ("Data/intro.csv")); Usersimilarity similarity =new pearsoncorrelationsimilarity (model); Userneighborhood Neighborhood =new Nearestnuserneighborhood (2,similarity,model); Recommender recommender= New Genericuserbasedrecommender (model,neighborhood,similarity); List<recommendeditem> Recommendations =recommender.recommend (1, 2); For (Recommendeditem reCommendation:recommendations) {SYSTEM.OUT.PRINTLN (recommendation);}} }  

Operation Result:

recommendeditem[item:104, value:4.257081]

recommendeditem[item:106, value:4.0]

The format of the intro.csv is as follows:

The first column is UserID, the second column is Itemid, and the third column preference Value is the rating 1,101,5 1,102,3 1,103,2.5 2,101,2 2,102,2.5 2,103,5 2,104,2 3,101,2.5 3,10 bis 3,105,4.5 3,107,5 4,101,5 4,103,3 4,104,4.5 4,106,4 5,101,4 5,102,3 5,103,2 5,104,4 5,105,3.5 5,106,4

The Pom.xml file is as follows:

<project xmlns= "http://maven.apache.org/POM/4.0.0" xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation= "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" > < Modelversion>4.0.0</modelversion> <groupId>zhzhl_zju</groupId> <artifactId>mahout< /artifactid> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name> Mahout</name> <url>http://maven.apache.org</url> <properties> < Project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies > <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> < version>3.8.1</version> <scope>test</scope> </dependency> <dependency> < Groupid>org.apache.mahout</groupid> <artifactId>mahout-core</artifactId> <version>0.4 </version> <type>jar</type> <scope>compile</scope> </dependency> </dependencies> </project>  

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.