human
I am working on the file "FDMS/TME4/TME4_FiltrageCollaboratif-Copy1.ipynb".
The first task is:
Collaboritive Filtering classes
Can you write Python code for it?

What is a the Python code you requested?
assistant
#Here is the Python code you requested.

class BaselineMean
human
def __init__(self):
        self.users={}
        self.movies={}
    def fit(self,train):
        for user in train:
            note=0
            for movie in train[user]:
                note+=train[user][movie]
            note=note/len(train[user])
            self.users[user]=note
        
    def predict(self,user,movie):
        return self.users[user]
    def score(self,X):
        nb_movies = len(get_moove(X))
        score = 0.0
        for user in X:
            for movie in X[user]:
                score += (self.predict(user,movie) - X[user][movie])**2
        return score/nb_movies
                
                    
    
class BaselineMeanMovie:
    def __init__(self):
        self.users={}
        self.movies={}
    def fit(self,train):
        movies = get_moove(train)
        for movie in movies:
            note=0
            cpt=0
            for user in train:
                try:
                    note+=train[user][movie]
                    cpt+=1
                except KeyError:
                    pass
            note=note/cpt
            self.movies[movie]=note
        
    def predict(self,user,movie):
        return self.movies[movie]
    def score(self,X):
        nb_movies = len(get_moove(X))
        score = 0.0
        for user in X:
            for movie in X[user]:
                score += (self.predict(user,movie) - X[user][movie])**2
        return score/nb_movies

baseline_mu= BaselineMeanUser()
baseline_mm= BaselineMeanMovie()

baseline_mu.fit(train)
baseline_mm.fit(train)

print("score baseline mean user  ",baseline_mu.score(test))
print("score baseline mean movie ",baseline_mm.score(test))