473,387 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.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).ratin gs())
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
Sep 23 '08 #1
1 795
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.

Sep 23 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Clarence Gardner | last post by:
The super object is considered a solution to the "diamond problem". However, it generally requires that the ultimate base class know that it is last in the method resolution order, and hence it...
11
by: Nicolas Lehuen | last post by:
Hi, I hope this is not a FAQ, but I have trouble understanding the behaviour of the super() built-in function. I've read the excellent book 'Python in a Nutshell' which explains this built-in...
9
by: Paul Rubin | last post by:
I'm trying the super() function as described in Python Cookbook, 1st ed, p. 172 (Recipe 5.4). class A(object): def f(self): print 'A' class B(object): def f(self):
2
by: Uwe Mayer | last post by:
Hi, I have a diamond-shaped multiple inheritanc chain with new style classes, but super() does not call the parent class correctly: -- snip -- from qtcanvas import * class B2(QCanvasItem):...
7
by: Kent Johnson | last post by:
Are there any best practice guidelines for when to use super(Class, self).__init__() vs Base.__init__(self) to call a base class __init__()? The super() method only works correctly in multiple...
4
by: John Salerno | last post by:
Here's some code from Python in a Nutshell. The comments are lines from a previous example that the calls to super replace in the new example: class A(object): def met(self): print 'A.met' ...
4
by: ddtl | last post by:
Hello everybody. Consider the following code: class A(object): def met(self): print 'A.met' class B(A): def met(self):
6
by: bjwillykajilly | last post by:
ok, so we're to right this program(in bluej) that consists of a few classes that will ultimately simulate a simple billfold(consisting of credit cards) a main card class, a drivers license, an id...
18
by: Richard Szopa | last post by:
Hello all, I am playing around w/ Python's object system and decorators and I decided to write (as an exercise) a decorator that (if applied to a method) would call the superclass' method of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.