Pyflix, confused about super() call

P

process

Anyone using Pyflix for the Netflix prize.

How can it call super to itself in its init-method?




---------------------


#!/usr/bin/env python

'''Sample baseline averaging algorithms.'''

import numpy as N
from pyflix.algorithms import Algorithm


class MovieAverage(Algorithm):
'''Baseline algorithm that computes the average of all the votes
for a movie
and predicts that for every user.

This algorithm returns an RMSE score of 1.0528 on the scrubbed
dataset.
'''

def __init__(self, training_set):
self._movie_averages = {}
super(MovieAverage,self).__init__(training_set)

def __call__(self, movie_id, user_id):
try: return self._movie_averages[movie_id]
except KeyError:
avg =
N.average(self._training_set.movie(movie_id).ratings())
self._movie_averages[movie_id] = avg
return avg


class UserAverage(Algorithm):
'''Baseline algorithm that computes the average of all the votes
for a user
and predicts that for every movie.

This algorithm returns an RMSE score of 1.0688 on the scrubbed
dataset.
'''

def __init__(self, training_set):
self._user_averages = {}
super(UserAverage,self).__init__(training_set)

def __call__(self, movie_id, user_id):
try: return self._user_averages[user_id]
except KeyError:
avg =
N.average(self._training_set.user(user_id).ratings())
self._user_averages[user_id] = avg
return avg


class DoubleAverage(MovieAverage,UserAverage):
'''Returns the average of L{MovieAverage} and L{UserAverage}.

This algorithm returns an RMSE score of 1.0158 on the scrubbed
dataset.
'''

def __call__(self, movie_id, user_id):
return (MovieAverage.__call__(self,movie_id,user_id) +
UserAverage.__call__(self,movie_id,user_id)) / 2
 
B

Bruno Desthuilliers

process a écrit :
Anyone using Pyflix for the Netflix prize.

How can it call super to itself in its init-method?

You mean :
class MovieAverage(Algorithm):
def __init__(self, training_set):
self._movie_averages = {}

this line ?

super(MovieAverage,self).__init__(training_set)


If that's what confuse you, I think you really should read the
FineManual(tm) instead of assuming Python is language X or Y.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top