I don't know how to write a code to load a CSV file or .inter file instead of the built in dataset in this example of evaluating a dataset as a recommender system:
from surprise import SVD
from surprise import KNNBasic
from surprise import Dataset
from surprise.model_selection import cross_validate
# Load the movielens-100k dataset (download it if needed).
data = Dataset.load_builtin('ml-100k')
# Use the famous SVD algorithm.
algo = KNNBasic()
# Run 5-fold cross-validation and print results.
cross_validate(algo, data, measures=['RMSE', 'MAE'], cv=5, verbose=True)
How would the full line of code be where I only need to input datapath and filename? I have tried the website for Surprise, but I didn't find anything. So I don't want the movielens code in the example, but instead a line that loads a datapath and file.
At first you need to create instance of
Reader()
:Note that
line_format
parameter can be only'rating user item'
(optionally'timestamp'
may be added) and these parameters has nothing to do with names of columns in yourcustom_rating.csv
. Thats whyskip_lines=1
prameter is defined (it skips first line in your csv file where usually column names are defined). On the other handline_format
parameter determines the order of columns. So just to be clear mycustom_ratings.csv
looks like this:Now you can create your
data
instance:Finally you can proceed with creating SVD model as shown in examples:
PS: And also don't forget to import libraries at the beginning of your code :)