<jupyter_start><jupyter_text>Preprocessing phase<jupyter_code>data_dict = {}
data_dict['books'] = books
data_dict['users'] = users
data_dict['ratings'] = ratings
preprocessed_data_dict = preprocessing(data_dict=data_dict, is_explicit=True, book_ratings_count_threshold=2, user_ratings_count_threshold=2)
preprocessed_data_dict['ratings'].head()
preprocessed_data_dict['ratings'] = preprocessed_data_dict['ratings'].rename({'User-ID': 'userID', 'ISBN': 'itemID', 'Book-Rating': 'rating'}, axis='columns')
preprocessed_data_dict['ratings'].head()<jupyter_output><empty_output><jupyter_text>Surprise experiments  Data reader<jupyter_code>reader = Reader(rating_scale=(1, 5))
data = Dataset.load_from_df(preprocessed_data_dict['ratings'][['userID', 'itemID', 'rating']], reader)<jupyter_output><empty_output><jupyter_text>SVD<jupyter_code>algo_svd = SVD()
cross_validate(algo_svd, data, measures=['RMSE', 'MAE'], cv=5, verbose=True, n_jobs=-1)<jupyter_output><empty_output><jupyter_text>NMF<jupyter_code>algo_nmf = NMF()
cross_validate(algo_nmf, data, measures=['RMSE', 'MAE'], cv=5, verbose=True, n_jobs=-1)<jupyter_output><empty_output><jupyter_text>KNN (Item-based)<jupyter_code>sim_options = {
    'name': 'cosine',
    'user_based': False
}
algo_knn = KNNBasic(k=5, sim_options=sim_options)
cross_validate(algo_knn, data, measures=['RMSE', 'MAE'], cv=5, verbose=True, n_jobs=1)<jupyter_output><empty_output><jupyter_text>KNN (User-based)<jupyter_code>sim_options = {
    'name': 'cosine'
}
algo_knn = KNNBasic(k=5, sim_options=sim_options)
cross_validate(algo_knn, data, measures=['RMSE', 'MAE'], cv=5, verbose=True, n_jobs=1)<jupyter_output><empty_output><jupyter_text>Grid search<jupyter_code>param_grid = {
    'n_epochs': [5, 10],
    'lr_all': [0.002, 0.005],
    'reg_all': [0.4, 0.6]
}
gs = GridSearchCV(SVD, param_grid, measures=['rmse', 'mae'], cv=5)
gs.fit(data)
print(gs.best_score['rmse'])
print(gs.best_params['rmse'])<jupyter_output>{'n_epochs': 10, 'lr_all': 0.005, 'reg_all': 0.4}
StarcoderdataJupyterStructuredCleanDedup