Mahout in aciotn

Source: Internet
Author: User
Tags cassandra
Mahout in aciotn

Jack Zhang is from the pioneer tribe. QQ: 248087140. welcome to join us!

This article welcomes reprint, reprint please indicate the source of http://my.oschina.net/u/1866370/blog/287907


I. Java and IDE (omitted)
Ii. MAVEN (Omitted) III. mahout Development Environment Construction

1, mahout Official Website: http://mahout.apache.org/

2, mahout official website on the mahout dependency page http://mahout.apache.org/general/downloads.html

Maven coordinates of mahout can be seen in 2

<dependency>    <groupId>org.apache.mahout</groupId>    <artifactId>mahout-core</artifactId>    <version>${mahout.version}</version></dependency>

Installation Process

Maven makes mahout environment setup easy and convenient. You only need to add the following content to Pom.

<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><mahout.version>0.6</mahout.version></properties><dependencies><dependency><groupId>org.apache.mahout</groupId><artifactId>mahout-core</artifactId><version>${mahout.version}</version></dependency><dependency><groupId>org.apache.mahout</groupId><artifactId>mahout-integration</artifactId><version>${mahout.version}</version><exclusions><exclusion><groupId>org.mortbay.jetty</groupId><artifactId>jetty</artifactId></exclusion><exclusion><groupId>org.apache.cassandra</groupId><artifactId>cassandra-all</artifactId></exclusion><exclusion><groupId>me.prettyprint</groupId><artifactId>hector-core</artifactId></exclusion></exclusions></dependency></dependencies>

Note:

1. MAVEN configuration description <mahout. version> 0.6 </mahout. version> above is to set the mahout version as the global variable of Maven. You can use <version >$ {mahout. version} </version> references the <exclusion> label to exclude dependencies during import. The jar package in the <exclusion> label excludes Org. mortbay. jetty. jetty, org. apache. cassandra. cassandra-all, me. prettyprint. hector-core, the second jar package, will be mentioned in future articles, 2. jar package description mahout-core is the mahout core package mahout-integration. If you import the coordinates of the jar packages of other projects, all the following JAR packages will be introduced. project (Including mahout related packages, httpclient, SOLR, Lucene, MongoDB and some frequently used toolkit in Java projects .) Org \ apache \ mahout-core \ 0.6 \ mahout-core-0.6.jarorg \ apache \ mahout-Math \ 0.6 \ mahout-math-0.6.jarorg \ uncommons \ maths \ uncommons-maths \ 1.2.2 \ uncommons-maths-1.2.2.jarjfree \ jcommon \ 1.0.12 \ jcommon-1.0.12.jarcom \ google \ guava \ R09 \ guava-r09.jarorg \ apache \ mahout-collections \ 1.0 \ mahout-collections-1.0.jarorg \ apache \ hadoop-core \ 0.20.204.0 \ hadoop-core-0.20.204.0.jarcommons-cli \ commons- CLI \ 1.2 \ commons-cli-1.2.jarcommons-httpclient \ commons-httpclient \ 3.0.1 \ commons-httpclient-3.0.1.jarcommons-logging \ commons-logging \ 1.0.3 \ commons-logging-1.0.3.jarcommons-codec \ commons-codec \ 1.4 \ commons-codec-1.4.jarcommons-configuration \ commons-Configuration \ 1.6 \ commons-configuration-1.6.jarcommons-collections \ commons- collections \ 3.2.1 \ commons-collections-3.2.1.jarcommons-digester \ commons-digester \ 1.8 \ commons-digester-1.8.jarcommons-beanutils \ commons-beanutils \ 1.7.0 \ commons-beanutils-1.7.0.jarcommons-beanutils \ commons-beanutils-core \ 1.8.0 \ commons-beanutils-core-1.8.0.jarorg \ codehaus \ Jackson-core- asl \ 1.8.2 \ jackson-core-asl-1.8.2.jarorg \ codehaus \ Jackson-mapper-Asl \ 1.8.2 \ jackson-mapper-asl-1.8.2.jarorg \ slf4j \ slf4j-api \ 1.6.1 \ slf4j-api-1.6.1.jarcommons-lang \ commons-lang \ 2.6 \ commons-lang-2.6.jarorg \ uncommons \ watchmaker \ watchmaker-framework \ 0.6.2 \ watchmaker-framework-0.6.2.jarcom \ thoughtworks \ xstream \ 1.3.1 \ xstream-1.3.1.jarxpp3 \ xpp3_min \ 1.1.4c \ xpp3_min-1.1.4c.jarorg \ apache \ Lucene-core \ 3.4.0 \ lucene-core-3.4.0.jarorg \ apache \ Lucene \ lucene-analyzers \ 3.4.0 \ lucene-analyzers-3.4.0.jarorg \ apache \ mahout \ commons-cli \ 2.0-mahout \ commons-cli-2.0-mahout.jarorg \ apache \ commons-Math \ 2.2 \ commons-math-2.2.jarorg \ apache \ mahout \ mahout-integration \ 0.6 \ mahout-integration-0.6.jarcommons-dbcp \ commons-DBCP \ 1.4 \ commons-dbcp-1.4.jarcommons-pool \ commons-pool \ 1.5.6 \ commons-pool-1.5.6.jarorg \ apache \ SOLR-commons-CSV \ 3.4.0 \ solr-commons-csv-3.4.0.jarorg \ MongoDB \ mongo-Java-driver \ 2.5 \ mongo-java-driver-2.5.jarorg \ MongoDB \ bson \ 2.5 \ bson-2.5.jar

Iv. hadoop (omitted)

For hadoop installation, see related articles under the hadoop category in this blog.

Mahout Programming

1. Recommend a product to a user

Step 1: Create a New Upload File, rename it as intro, copy it to intro.txt, and change the suffix to CSV. In actual development, we will also obtain similar log data as an input file.

1,101,5.01,102,3.01,103,2.5 2,101,2.02,102,3.02,103,5.02,104,2.0 3,101,2.53,104,4.03,105,4.53,107,5.0 4,101,5.04,103,3.04,104,4.54,106,4.0 5,101,4.05,102,3.05,103,2.05,104,4.05,105,3.55,106,4.0

Step 2: compile a user-based collaborative filtering program

Requirement: to recommend an item to a user with ID 1, the recommended item number is 1.

Class recommenderintro {final static int neighborhood_num = 2; Final Static int user_id = 1; Final Static int recommend_num = 1; public static void main (string [] ARGs) throws ioexception, tasteexception {/** build the file object. Note that the file path must be correct */datamodel model = new filedatamodel (new file ("intro.csv ")); /** user acquaintance */usersimilarity user = new pearsoncorrelationsimilarity (model);/** nearest neighbor */userneighborhood neighborhood = new neighbor (neighborhood_num, user, model ); /** generate recommender */recommender = new genericuserbasedrecommender (model, neighborhood, user);/** for recommendation, recommend one item to a user with ID 1 */list <recommendeditem> recommendations = recommender. recommend (user_id, recommend_num); For (recommendeditem recommendation: Recommendations) {system. out. println (recommendation );}}}

Recommendation results

RecommendedItem[item:104, value:4.257081]

2. Score the recommendation Program



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.