mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grant Ingersoll <gsing...@apache.org>
Subject Re: Trying to build simple recommender, but getting SQLException
Date Mon, 12 Oct 2009 20:49:42 GMT
I'm pretty sure that user id's now need to be longs.

On Oct 12, 2009, at 4:28 PM, Larry Homes wrote:

> Hello,
>
> I am trying to just build a simple Recommender system using a
> SlopeOneRecommender. I used the sample table schema and data found  
> in the
> javadoc here:
> http://lucene.apache.org/mahout/javadoc/core/org/apache/mahout/cf/taste/impl/model/jdbc/MySQLJDBCDataModel.html

> .
> Here is a select * from the table:
>
> mysql> select * from taste_preferences;
> +---------+---------+------------+
> | user_id | item_id | preference |
> +---------+---------+------------+
> | abc     | 123     |        0.9 |
> | abc     | 456     |        0.1 |
> | def     | 123     |        0.2 |
> | def     | 789     |        0.3 |
> +---------+---------+------------+
> 4 rows in set (0.00 sec)
>
>
> When I try to run the recommender I get this error:
>
> java.util.NoSuchElementException: Can't retrieve more due to
> exception: java.sql.SQLException: Invalid value for getLong() - 'abc'
> 	org.apache.mahout.cf.taste.impl.model.jdbc.AbstractJDBCDataModel 
> $ResultSetIDIterator.nextLong(AbstractJDBCDataModel.java:684)
> 	 
> org.apache.mahout.cf.taste.impl.recommender.slopeone.MemoryDiffStorage.buildAverageDiffs

> (MemoryDiffStorage.java:220)
> 	 
> org.apache.mahout.cf.taste.impl.recommender.slopeone.MemoryDiffStorage 
> .<init>(MemoryDiffStorage.java:115)
> 	 
> org.apache.mahout.cf.taste.impl.recommender.slopeone.SlopeOneRecommender 
> .<init>(SlopeOneRecommender.java:63)
> 	Recommend.doGet(Recommend.java:67)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
> 	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>
>
>
> Here is the code:
>
> //Bunch of imports here
>
> public class Recommend extends HttpServlet
> {
>    private static final long serialVersionUID = 1L;
>    DataSource ds = null;
>
>    public void init()
>    {
>        String DATASOURCE =
> getServletContext().getInitParameter("DataSource");
>
>        try
>        {
>            super.init();
>
>            if ((ds = (DataSource) (new
> InitialContext().lookup(DATASOURCE))) == null)
>                throw new ServletException("Error configuring  
> DataSource.");
>        }
>        catch (NamingException e)
>        {
>            // TODO Auto-generated catch block
>            e.printStackTrace();
>        }
>        catch (ServletException e)
>        {
>            // TODO Auto-generated catch block
>            e.printStackTrace();
>        }
>    }
>
>    protected void doGet(HttpServletRequest request,  
> HttpServletResponse
> response) throws ServletException, IOException
>    {
>        PrintWriter pw = response.getWriter();
>        DataModel model = new MySQLJDBCDataModel(ds,  
> "taste_preferences",
> "user_id", "item_id", "preference");
>        // Make a weighted slope one recommender
>        Recommender recommender;
>        Recommender cachingRecommender;
>        try
>        {
>            recommender = new SlopeOneRecommender(model);
>            cachingRecommender = new CachingRecommender(recommender);
>            List<RecommendedItem> l = cachingRecommender.recommend 
> (123, 2);
>            Iterator<RecommendedItem> i = l.iterator();
>
>            while(i.hasNext())
>            {
>                pw.println(i.next().getItemID());
>            }
>
>        } catch (TasteException e)
>        {
>            // TODO Auto-generated catch block
>            e.printStackTrace();
>        }
>    }
>
>    protected void doPost(HttpServletRequest request,  
> HttpServletResponse
> response) throws ServletException, IOException
>    {
>
>    }
>
> }
>
>
> If you need any other data, feel free to ask.
>
> Thanks

--------------------------
Grant Ingersoll
http://www.lucidimagination.com/

Search the Lucene ecosystem (Lucene/Solr/Nutch/Mahout/Tika/Droids)  
using Solr/Lucene:
http://www.lucidimagination.com/search


Mime
View raw message