Mahout Integration with Grails

Posted By : Varun Sharma | 19-Jun-2012

I have integrated mahout in one of my projects in grails so I wanted to share some thoughts on how Apache Mahout might be integrated with grails.

 

First of all What is Apache Mahout ?

 

The Apache Mahout™ machine learning library's goal is to build scalable machine learning libraries. Mahout has Collaborative Filtering, User and Item based recommenders. 

To start working with Mahout you will need to install Mahout on your system 

 

Installing Mahout, the Ubuntu edition

 

For Mahout installation you need 3 things:

1. Install JDK 1.6 or higher

2. Install Maven

3. Install Mahout

After successful Mahout installation you have to add Mahout Recommender plugin for grails.

 

What Mahout Recommender plugin is all about ?

 

The Mahout Recommender plugin enabled you to use Apache Mahout recommendation algorithms in your Grails project. With the plugin, you can find an effective recommender, evaluating precision and recall, and evaluating the performance of the selected recommender without writing single line of code.

There are two ways to install Mahout Recommender Plugin in grails:

1. You can use the command grails install-plugin mahout-recommender in grails command prompt. or

2. Use the right click option on plugins (under your project) select the plugin from the window & select install then OK.

After the plugin installed into your project, the following configurations will be appended to your project's Config.groovy file:

// Added by the Mahout Recommender plugin:
mahout.recommender.mode = 'input'  // 'input', 'config' or 'class'

The plugin support both the file data model and MySQL data model.

For file data model, no additional configuration is required to make use of command line tool of the plugin, but the data file must be located in classpath such asgrails-app/conf and data file name must be specified in mahout.recommender.data.file for web-based tools such as recommenders' evaluator and recommender.

For MySQL data model, change mahout.recommender.data.model from 'file' to 'mysql' and configure the DataSource.groovy properly.

For Basic Configurations(refer)

ttp://limcheekin.github.com/mahout-recommender/docs/manual/guide/configuration.html

 

Steps to Setup Mahout Recommendation Plugin with MySQL:

 

The plugin is using file data model by default, this section will described step-by-step of how to setup your project to use MySQL data model with assumption that MySQL database is pre-installed and started in your development workstation.

Simple steps to work with MySQL:

1. Login to MySQL using command:  mysql -u root

2. Create recommender database using command:  create database recommender

3. You should have MySQL Connector/J plugin installed in grails.

4. Update mahout.recommender.data.model in grails-app/conf/Config.groovy from 'file' to 'mysql'.

5. Update database configurations in grails-app/conf/DataSource.groovy from HSQL or H2 to MySQL.

mahout.recommender.data.model = 'mysql' // 'file' or 'mysql'
dataSource {

    pooled = true
    driverClassName = "com.mysql.jdbc.Driver"
    username = "root"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
            url = "jdbc:mysql://localhost:3306/recommender"
        }
    }
    test {
        dataSource {
            dbCreate = "create-drop"          
            url = "jdbc:mysql://localhost:3306/recommender"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:mysql://localhost:3306/recommender"
        }
    }
}


 

>Hope it helps !

 

Varun Sharma
[email protected]

http://oodlestechnologies.com/

About Author

Author Image
Varun Sharma

Varun is an experienced Groovy and Grails developer and has worked extensively on designing and developing applications with FaceBook , Linkedin and Twitter integrations using Grails technologies. Varun loves painting and photography.

Request for Proposal

Name is required

Comment is required

Sending message..