Attempting Getting Started Python script in Release 0.6.0 Lenskit Documentation

42 views
Skip to first unread message

Bill Noffsinger

unread,
Mar 13, 2019, 11:34:49 AM3/13/19
to LensKit Recommender Toolkit Development and Support
I assume the getting started document covers a Python script in Jupyter Notebook.  I have Anaconda Navigator 1.9.6 and have the latest Python installed, When entering the script I receive an error on the %matplotlib inline 
statement. I can comment that out and continue since it is not used until later in the script. 

I receive this result early in the script. The data values look correct but the NaN values suggest an error to me.

user item rating timestamp
0 196\t242\t3\t881250949 NaN NaN NaN
1 186\t302\t3\t891717742 NaN NaN NaN
2 22\t377\t1\t878887116 NaN NaN NaN
3 244\t51\t2\t880606923 NaN NaN NaN
4 166\t346\t1\t886397596 NaN NaN NaN


After running the script to this point:

# -*- coding: utf-8 -*-
"""
Created on Thu Feb 21 14:09:48 2019

@author: william.noffsinger
"""

from lenskit import batch, topn, util
from lenskit import crossfold as xf
from lenskit.algorithms import Recommender
from lenskit.algorithms import als
from lenskit.algorithms import item_knn as knn
from lenskit import topn

import numpy

import pandas as pd
#%matplotlib inline
ratings = pd.read_csv('C:/Users/william.noffsinger/Lenskit/ml-100k/ml-100k/u.data', sep='t', names=['user', 'item', 'rating', 'timestamp']) 
ratings.head()

algo_ii = knn.ItemItem(20)
algo_als = als.BiasedMF(50)

def eval(aname, algo, train, test):
    fittable = util.clone(algo)
    fittable = Recommender.adapt(fittable)
    fittable.fit(train)
    users = test.user.unique()
    recs = batch.recommend(fittable, users, 100)
    recs['Algorithm'] = aname
    return recs

all_recs = []
test_data = []
for train, test in xf.partition_users(ratings[['user', 'item', 'rating']], 5, xf.SampleFrac(0.2)):
    test_data.append(test)
    all_recs.append(eval('ItemItem', algo_ii, train, test))
    all_recs.append(eval('ALS', algo_als, train, test))
    #####
    all_recs = pd.concat(all_recs, ignore_index=True)
    all_recs.head()    
    

I receive an error: ValueError: zero-size array to reduction operation maximum which has no identity

and looking at the Variable Explorer in Spyder  I see the all_recs list size is zero and the test_data list size is 1. 

I assume I have the correct environment for Python, Anaconda, etc. 

Any tips would be appreciated.



Michael Ekstrand

unread,
Mar 13, 2019, 12:06:44 PM3/13/19
to Bill Noffsinger, LensKit Recommender Toolkit Development and Support
Bill,

It looks like your 'read_csv' call doesn't have the right 'sep': it should be "sep='\t'", not "sep='t'". This can be seen in the dump of the data table: the 'item' column has tab-separated numbers in it.

Hope that helps and clears it up! Yes, this is a Jupyter notebook.

- Michael

--
You received this message because you are subscribed to the Google Groups "LensKit Recommender Toolkit Development and Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lenskit-recsy...@googlegroups.com.
To post to this group, send email to lenskit...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lenskit-recsys/9df4546a-e1a4-481b-8907-82624340287a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Michael D. Ekstrand — michael...@boisestate.edu https://md.ekstrandom.net
Assistant Professor, Dept. of Computer Science, Boise State University
People and Information Research Team (PIReT)  http://coen.boisestate.edu/piret/

Bill Noffsinger

unread,
Mar 13, 2019, 3:16:35 PM3/13/19
to Michael Ekstrand, Bill Noffsinger, LensKit Recommender Toolkit Development and Support

Yes, I fixed my typos and the script ran fine - thanks. Now I will study the docs and code and start making some mods as I learn more of the details. Python (Spyder) still gives me a syntax error on the matplotlib but I will move on.


matplotlib.axes._subplots.AxesSubplot at 0x7f03842f8860>     gets a syntax error in Spyder


Many thanks!




From: lenskit...@googlegroups.com <lenskit...@googlegroups.com> on behalf of Michael Ekstrand <michael...@boisestate.edu>
Sent: Wednesday, March 13, 2019 12:06:22 PM
To: Bill Noffsinger
Cc: LensKit Recommender Toolkit Development and Support
Subject: Re: Attempting Getting Started Python script in Release 0.6.0 Lenskit Documentation
 

NSU Security WARNING: This is an external email. Do not click links or open attachments unless you recognize the sender and know that the content is safe.


Bill Noffsinger

unread,
Sep 20, 2019, 12:26:53 PM9/20/19
to LensKit Recommender Toolkit Development and Support
Doe the current LKPY Lenskit have an algorithm implementation for a Restricted Boltzmann Machine, Recurrent Neural Network or other deep learning implementation? 

Michael Ekstrand

unread,
Sep 20, 2019, 3:18:59 PM9/20/19
to Bill Noffsinger, LensKit Recommender Toolkit Development and Support
Not currently.

We would welcome either an implementation or a bridge to an implementation in another library. Bridges are often preferable, to decrease LensKit code maintenance.

- Michael

--
You received this message because you are subscribed to the Google Groups "LensKit Recommender Toolkit Development and Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lenskit-recsy...@googlegroups.com.


--
Michael D. Ekstrand — michael...@boisestate.edu https://md.ekstrandom.net
Assistant Professor, Dept. of Computer Science, Boise State University
People and Information Research Team (PIReT)  http://coen.boisestate.edu/piret/
I may send mail outside of working hours; I do not expect you to. He/him.

Bill Noffsinger

unread,
Sep 27, 2019, 3:00:42 PM9/27/19
to LensKit Recommender Toolkit Development and Support
I'm experimenting with the Getting Started script in LKPY: 

I wish to display RMSE and MAE metrics. 

I have imported  the predict module as in
     from lenskit.metrics import predict                         no errors or warnings are produced

Next I coded these two lines per page 16 in the LKPY doc:

      preds = predict(algo, pairs)
      user_rmse = preds.groupby('user').apply(lambda df: rmse(df.prediction, df.rating))

Python then says that algo, pairs, rmse are undefined  ??


On Wednesday, March 13, 2019 at 11:34:49 AM UTC-4, Bill Noffsinger wrote:

Michael Ekstrand

unread,
Sep 27, 2019, 7:17:00 PM9/27/19
to Bill Noffsinger, LensKit Recommender Toolkit Development and Support
Bill,

That example is not complete - it assumes you have variables 'algo' and 'pairs' that contain your algorithm and your test data.

I will update the example to be runnable.

- Michael

--
You received this message because you are subscribed to the Google Groups "LensKit Recommender Toolkit Development and Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lenskit-recsy...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages