0
$\begingroup$

I am building a recommender system using the Sushi Preference Dataset and the NMF (Non-negative Matrix Factorization) model. I am implementing the same using the Surprise library. I want to use Randomized Search CV for hyperparameter tuning. However, when I attempt to run the following code:

import sys
import os
import pandas as pd
import numpy as np

sushi = pd.read_csv(os.path.join('Datasets','Sushi','sushi3-2016', 'sushi3b.5000.10.score'), sep=' ', header=None, low_memory=False)

sushi_names = {0:'ebi', 1:'anago', ... 87: 'tobiuo', 12: 'akagai'}
# A dictionary of 100 sushi names

sushi = sushi.rename(columns=sushi_names)
sushi = sushi+1 # to convert -1 to 0, 0 to 1, etc.

sushi = pd.melt(sushi.reset_index(), id_vars='index', value_vars=sushi.columns)
sushi.columns = ['user_id', 'item_id', 'rating']
# to create a user-item-rating dataframe

# Create a Reader object to specify the rating scale
reader = Reader(rating_scale=(1, 5)) # the ratings are on the scale of 1 to 5.
data = Dataset.load_from_df(sushi, reader)

# Define the algorithm to use
algo = surprise.prediction_algorithms.matrix_factorization.NMF(biased=True, random_state=42, verbose=False)

# The parameter grid to search through
param_grid = {'n_factors':[10,15,20], 'reg_pu':[0.03,0.06,0.09], 'reg_qi':[0.03,0.06,0.09], 'reg_bu':[0.01,0.02,0.03], 'reg_bi':[0.01,0.02,0.03], 'lr_bu':[0.003,0.005,0.007], 'lr_bi':[0.003,0.005,0.007]}

param_search = surprise.model_selection.RandomizedSearchCV(algo, param_grid, measures=['rmse', 'mae'], n_jobs=1, cv=5)

# fit the data to the algorithm
# This is the step which is throwing the error.
param_search.fit(data)

print(param_search.best_score)
print(param_search.best_params)
print(param_search.best_estimator)
print(param_search.cv_results)
print(param_search.best_index)

I receive a TypeError: 'NMF' object is not callable error corresponding to the line: param_search.fit(data).

I have checked the documentation for the required input types and outputs, and thoroughly reviewed the examples, but I am failing to determine what is causing the error. How can I resolve this issue?

$\endgroup$

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.