This is just to show that the import errors which were encountered during the installation of Crab, a Recommender Framework in Python  worked fine with the fixes I earlier outlined.

These were the errors and how they were fixed:

  1. ImportError: No module named ‘scikits
  2. ImportError: No module named learn.base

 

The code below is the example of how the Crab Recommender Works as outlined by Crab:

In [3]:

from scikits.crab import datasets

 

In [4]:
movies = datasets.load_sample_movies()

 

In [5]:
songs = datasets.load_sample_songs()

 

In [6]:
import pprint ## to make printed items clearer
pprint.pprint(movies.data)

 

{1: {1: 3.0, 2: 4.0, 3: 3.5, 4: 5.0, 5: 3.0},
 2: {1: 3.0, 2: 4.0, 3: 2.0, 4: 3.0, 5: 3.0, 6: 2.0},
 3: {2: 3.5, 3: 2.5, 4: 4.0, 5: 4.5, 6: 3.0},
 4: {1: 2.5, 2: 3.5, 3: 2.5, 4: 3.5, 5: 3.0, 6: 3.0},
 5: {2: 4.5, 3: 1.0, 4: 4.0},
 6: {1: 3.0, 2: 3.5, 3: 3.5, 4: 5.0, 5: 3.0, 6: 1.5},
 7: {1: 2.5, 2: 3.0, 4: 3.5, 5: 4.0}}
In [7]:
pprint.pprint(movies.user_ids)

 

{1: 'Jack Matthews',
 2: 'Mick LaSalle',
 3: 'Claudia Puig',
 4: 'Lisa Rose',
 5: 'Toby',
 6: 'Gene Seymour',
 7: 'Michael Phillips'}
In [8]:
pprint.pprint(movies.item_ids)

 

{1: 'Lady in the Water',
 2: 'Snakes on a Planet',
 3: 'You, Me and Dupree',
 4: 'Superman Returns',
 5: 'The Night Listener',
 6: 'Just My Luck'}
In [9]:
from scikits.crab.models import MatrixPreferenceDataModel

 

In [10]:
#Build the model
model = MatrixPreferenceDataModel(movies.data)

 

In [11]:
from scikits.crab.metrics import pearson_correlation

 

In [12]:
from scikits.crab.similarities import UserSimilarity

 

In [13]:
#Build the similarity
similarity = UserSimilarity(model, pearson_correlation)

 

In [14]:
from sklearn.base import BaseEstimator

 

In [15]:
from scikits.crab.recommenders.knn import UserBasedRecommender

 

In [16]:
#build the user Based recommender
recommender = UserBasedRecommender(model, similarity, with_preference=True)

 

In [17]:
#recommend item for the user 5 (Toby)
recommender.recommend(5)

 

C:\Users\adaba\Anaconda3\envs\gl-env\lib\site-packages\scikits\crab\recommenders\knn\classes.py:538: VisibleDeprecationWarning: boolean index did not match indexed array along dimension 0; dimension is 5 but corresponding boolean dimension is 4
  similarities = similarities[~np.isnan(prefs)]
Out[17]:
[(5, 3.3477895267131013), (1, 2.8572508984333034), (6, 2.4473604699719846)]
Watch a quick video of the fix here:

Similar Posts

2 Comments

    1. Hi Soufiane,
      just do a full import. hence instead of “from crab.recommenders.knn import UserBasedRecommender” put scikits infront of the crab. So it should be like this.
      “from scikits.crab.recommenders.knn import UserBasedRecommender”
      Let me know if that helps.

Leave a Reply

Your email address will not be published. Required fields are marked *