Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Cross Validate with a Pandas Dataframe, running into datatype error #450

Open
JackRaines opened this issue Nov 30, 2022 · 0 comments

Comments

@JackRaines
Copy link

Description

from future import (absolute_import, division, print_function,
unicode_literals)

import pandas as pd

from surprise import SVD
from surprise import dataset
from surprise import Reader

reader = Reader()
model = SVD()
ratings_dict=ratings.to_dict('records')
ratings_dict

Example output: [{'userId': 1, 'movieId': 31, 'rating': 2.5, 'timestamp': 1260759144},
{'userId': 1, 'movieId': 1029, 'rating': 3.0, 'timestamp': 1260759179},
{'userId': 1, 'movieId': 1061, 'rating': 3.0, 'timestamp': 1260759182},
{'userId': 1, 'movieId': 1129, 'rating': 2.0, 'timestamp': 1260759185},

df = pd.DataFrame.from_dict(ratings_dict)

You'll need to create a dummy reader

reader = Reader(line_format='user item rating', rating_scale=(1, 5))

Also, a dummy Dataset class

class MyDataset(dataset.DatasetAutoFolds):

def __init__(self, df, reader):

    self.raw_ratings = [(uid, iid, r, None) for (uid, iid, r) in
                        zip(df['userId'], df['movieId'], df['rating'])]
    self.reader=reader

data = MyDataset(df, reader)

cross_validate(model,data,measures=['userId', 'movieId', 'rating'],cv=3)

Error Message: AttributeError: module 'surprise.accuracy' has no attribute 'userid'
1 cross_validate(model,data,measures=['userId', 'movieId', 'rating'],cv=3)

Steps/Code to Reproduce

Before running the above code:

ratings=pd.read_csv('ratings_small.csv')
ratings.head()

!pip install scikit-surprise
from surprise import Reader, Dataset, SVD
from surprise.model_selection import cross_validate

Expected Results

Actual Results

Versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant