In this part of the exercise, you will implement the collaborative filtering learning algorithm and apply it to a dataset of movie ratings.2 This dataset consists of ratings on a scale of 1 to 5. The dataset has n**u = 943 users, and n*m = 1682 movies.
from scipy.optimize import minimize res=minimize(fun=costFunction,x0=params,args=(Y_norm,R,nm,nu,nf,lamda),method='TNC',jac=costGradient,options={'maxiter':100})
movies=[] with open('movie_ids.txt','r',encoding='latin 1')as f: for line in f: tokens=line.strip().split(' ') movies.append(' '.join(tokens[1:]))
len(movies) 1682
for i in range(10): print(index[i],movies[index[i]],y_pred[index[i]])
120 Independence Day (ID4) (1996) 5.449120842440642 49 Star Wars (1977) 5.352125183811118 180 Return of the Jedi (1983) 5.319959550159248 171 Empire Strikes Back, The (1980) 5.182303379024724 173 Raiders of the Lost Ark (1981) 5.170746823498372 95 Terminator 2: Judgment Day (1991) 5.109846973143337 312 Titanic (1997) 5.042844020713496 194 Terminator, The (1984) 5.026389017143506 1466 Saint of Fort Washington, The (1993) 5.0090202813542275 209 Indiana Jones and the Last Crusade (1989) 5.008614086836323