5
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'

第一行,从意外导入 Reader, Dataset, SVD 工作正常。就是这样,它无法从惊喜包中导入评估。

我已经使用 conda 安装了 scikit-surprise。我认为它已成功安装。

4

3 回答 3

10

从 2020 年 1 月开始,请改为执行以下操作...

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)

于 2020-01-03T03:26:20.510 回答
8

根据文档,该evaluate()方法在版本 1.0.5 中已弃用(功能上由 替换model_selection.cross_validate())并在版本 1.1.0 中被删除,这可能是您安装的。

于 2019-11-30T04:07:36.793 回答
0

正如@merv 所述,evaluate()方法在版本 1.0.5 中已弃用。这是一个经过测试的工作示例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)

训练模型

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

预测

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

您可以阅读文档以获取更多详细信息。

于 2022-01-25T10:40:12.863 回答