Pyflix, confused about super() call

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • process

    Pyflix, confused about super() call

    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.algorith ms import Algorithm


    class MovieAverage(Al gorithm):
    '''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_ave rages = {}
    super(MovieAver age,self).__ini t__(training_se t)

    def __call__(self, movie_id, user_id):
    try: return self._movie_ave rages[movie_id]
    except KeyError:
    avg =
    N.average(self. _training_set.m ovie(movie_id). ratings())
    self._movie_ave rages[movie_id] = avg
    return avg


    class UserAverage(Alg orithm):
    '''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_aver ages = {}
    super(UserAvera ge,self).__init __(training_set )

    def __call__(self, movie_id, user_id):
    try: return self._user_aver ages[user_id]
    except KeyError:
    avg =
    N.average(self. _training_set.u ser(user_id).ra tings())
    self._user_aver ages[user_id] = avg
    return avg


    class DoubleAverage(M ovieAverage,Use rAverage):
    '''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,mo vie_id,user_id) +
    UserAverage.__c all__(self,movi e_id,user_id)) / 2
  • Bruno Desthuilliers

    #2
    Re: Pyflix, confused about super() call

    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(Al gorithm):
    def __init__(self, training_set):
    self._movie_ave rages = {}
    this line ?

    super(MovieAver age,self).__ini t__(training_se t)


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

    Comment

    Working...