7
from surprise import Reader, Dataset, SVD
from surprise import evaluate
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-12-6d771df269b8> in <module>()
----> 1 from surprise import evaluate

ImportError: cannot import name 'evaluate'

The first line, from surprise import Reader, Dataset, SVD works fine. Just that, it's not able to import the evaluate from the surprise package.

I have installed the scikit-surprise using conda. I think it was installed successfully.

Tushar
  • 93
  • 1
  • 1
  • 7

3 Answers3

11

As of January 2020, do something like the following instead...

from surprise import SVD
from surprise import Dataset
from surprise.model_selection import cross_validate

# Load the dataset (download it if needed)
data = Dataset.load_builtin('ml-100k')

# Use the famous SVD algorithm
algo = SVD()

# Run 5-fold cross-validation and then print results
cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)

Kris Stern
  • 1,192
  • 1
  • 15
  • 23
10

According to the documentation, the evaluate() method was deprecated in version 1.0.5 (functionally replaced by model_selection.cross_validate()) and was removed in version 1.1.0, which is likely what you have installed.

merv
  • 67,214
  • 13
  • 180
  • 245
1

As mentioned by @merv, evaluate() method is deprecated in version 1.0.5. This is a working example tested with scikit-surprise==1.1.1:

import pandas as pd
from surprise import SVD, Reader
from surprise import Dataset
from surprise.model_selection import cross_validate

reader = Reader()
csv = pd.read_csv('yourdata.csv')

# Loading local dataset
data = Dataset.load_from_df(csv, reader)

# Use SVD algorithm or other models
model = SVD()

# cross-validation with no. of kfold=5 (can be changed per your need)
cross_validate(model, data, measures=['rmse', 'mae'], cv=5)

Train the model

data_train = data.build_full_trainset()
model.fit(data_train)

Predict

model.predict(uid=<e.g. 1>, iid=<e.g. 2>)

You can read the documentation for more details.

Hossein Kalbasi
  • 1,641
  • 2
  • 13
  • 26