1

I am trying to make an recommender system using SVD python package. I am importing csv file then doing the below operation, but it is showing error. How to solve this?

from surprise import SVD,Reader,Dataset
ratings =  pd.read_csv("/content/ratings_small.csv")
data = Dataset.load_from_df(ratings[['userId','movieId','rating']],reader)
data.split(n_folds=5)
---------------------------------------------------------------------------

AttributeError                            Traceback (most recent call last)

<ipython-input-29-f3bf344cf3e2> in <module>()
----> 1 data.split(n_folds=5)

AttributeError: 'DatasetAutoFolds' object has no attribute 'split'

It says it has not split attribute buti went through a question where they have used it.

Chidananda Nayak
  • 1,161
  • 1
  • 13
  • 45
  • 1
    1) question has nothing to do with `svd` (removed) - and your title is misleading 2) where does `Dataset.load_from_df` come from (which the error is obviously about)? Please include explicitly your (relevant only) imports (I guess it's from `surprise`, but this should not be a reader's guess). – desertnaut Apr 19 '20 at 14:14

1 Answers1

3

You need to import KFold from model_selection to split the data and perform cross validation. This works.

from surprise import SVD,Reader,Dataset
from surprise.model_selection import KFold
ratings =  pd.read_csv("/content/ratings_small.csv")
data = Dataset.load_from_df(ratings[['userId','movieId','rating']],reader)
kf = KFold(n_splits=5)
kf.split(data)
  • This [link](https://stackoverflow.com/questions/62046795/attributeerror-datasetautofolds-object-has-no-attribute-split) has another way of doing it – sakeesh Sep 08 '21 at 01:24