mahout-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gökhan Çapan <gkhn...@gmail.com>
Subject Re: Trying to build simple recommender, but getting SQLException
Date Wed, 14 Oct 2009 07:54:58 GMT
BTW, you have that line in your code:

List<RecommendedItem> l = cachingRecommender.recommend(123, 2);

I think you'll try to recommend items for an item. That is not possible even
if you fix your database.
If you want to recommend items for an item, you should use an item based
recommender, and its mostSimilarItems function

On Mon, Oct 12, 2009 at 11:28 PM, Larry Homes <larr.homes@gmail.com> 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
>



-- 
Gökhan Çapan

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message