Skip to main content

Predikon: Sub-Matrix Factorization for Real-Time Vote Prediction

Project description


Sub-Matrix Factorization for Real-Time Vote Prediction

Build Status Coverage Status PyPI Downloads

The predikon library is the Python library for the algorithm proposed in

Alexander Immer*, Victor Kristof*, Matthias Grossglauser, Patrick Thiran, Sub-Matrix Factorization for Real-Time Vote Prediction, KDD 2020

The predikon algorithm enables you to predict aggregate vote outcomes (e.g., national) from partial outcomes (e.g., regional) that are revealed sequentially. See the usage documentation more details on how to use this library or read the paper linked above for more details on how the algorithm works.

It is the algorithm powering, a platform for real-time vote prediction in Switzerland.


To install the Predikon library from PyPI, run

pip install predikon

Getting Started

Given a dataset Y of historical vote results collected in an array of R regions and V votes, given a vector y of partial results, and given an optional weighting w per region (e.g., the number of valid votes in each region), it is easy to predict the unobserved entries of y after observing at least one regional result (one entry of y) of an ongoing referendum or election:

from predikon import LogisticSubSVD
model = LogisticSubSVD(Y, w)
pred = model.fit_predict(y)
# All unobserved entries in `y` are now filled in.

You can then obtain a prediction for the aggregate outcome (assuming the weights are the number of valid votes in this example) as:

N = w.sum()  # Total number of votes.
ypred = / N
ytrue = / N
print(abs(ypred - ytrue))

Have a look at the example notebook for a complete example of how to use the predikon library (with Swiss referenda).

Going Further

You can find further information in:

And don't hesitate to reach out us if you have questions or to open issues!


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

predikon-0.4.tar.gz (8.3 kB view hashes)

Uploaded source

Built Distribution

predikon-0.4-py3-none-any.whl (8.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page