The reference implementation of the SPEAR ranking algorithm in Python.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


The reference implementation of the SPEAR ranking algorithm in Python.


The purpose of this implementation is to make the inner workings of the SPEAR algorithm easy to understand and not to distract or confuse the reader with highly optimized code.

The SPEAR algorithm takes a list of user activities on resources as input, and returns ranked lists of users by expertise scores and resources by quality scores, respectively.

Using SPEAR to simulate the HITS algorithm

You can also use this library to simulate the HITS algorithm of Jon Kleinberg. Simply supply a credit score function C(x) = 1 to the SPEAR algorithm (see documentation of


You can now download and install SPEAR from Python Package Index (aka Python Cheese Shop) via setuptools/easy_install. Just run

$ easy_install Spear

After installation, a simple import deliciousapi in your Python scripts will do the trick.

An alternative installation method is downloading the code straight from the git repository.

The SPEAR Python library requires SciPy/NumPy. If you don’t have these installed already, here are some installation instructures to get you started.


If you used setuptools/easy_install for installation, you can update Spear via

$ easy_install -U Spear

Alternatively, if you downladed the code from the git repository, simply pull the latest changes.


The algorithm requires a list of user activities on resources as input. More specifically, it requires a list of (timestamp, user, resource) tuples.

>>> import spear
>>> activities = [
... (datetime.datetime(2010,7,1,9,0,0), "alice", ""),
... (datetime.datetime(2010,8,1,12,45,0), "bob", ""),
... ]
>>> spear_algorithm = spear.Spear(activities)
>>> expertise_results, quality_results =

Get the top user and his expertise score:

>>> expertise_score, user = expertise_results[0]
>>> print "%s => %.4f" % (user, expertise_score)
alice => 0.5858

Get the top resource and its quality score:

>>> quality_score, resource = quality_results[0]
>>> print "%s => %.4f" % (resource, quality_score) => 1.0000

More information

You can find more information about the SPEAR algorithm at:


The code is licensed to you under version 2 of the GNU General Public License.


Copyright 2009-2010 Michael G. Noll, Ching-man Au Yeung