Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #106969

Looking for feedback on weighted voting algorithm

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From justin walters <walters.justin01@gmail.com>
Newsgroups comp.lang.python
Subject Looking for feedback on weighted voting algorithm
Date Wed, 13 Apr 2016 19:37:13 -0700
Lines 40
Message-ID <mailman.89.1460601435.15650.python-list@python.org> (permalink)
References <CAO1D73EFoLoJm=4shNfgEsJinGHrM82J_BsTRMnm7XX4tW1h+A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de G2t45L/B9vUq7lQTaBL+UgvUDgURuIHMlYy7AsBbrBcg==
Return-Path <walters.justin01@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.019
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'essentially': 0.04; '"""': 0.05; '__name__': 0.07; '3),': 0.09; 'def': 0.13; "'__main__':": 0.16; '1),': 0.16; '2),': 0.16; '4),': 0.16; 'input.': 0.16; 'python3.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'all,': 0.20; 'algorithm': 0.20; 'tuples': 0.22; 'written': 0.24; 'wondering': 0.25; 'message-id:@mail.gmail.com': 0.27; 'voting.': 0.29; "i'm": 0.30; 'received:209.85.215.46': 0.30; 'anyone': 0.32; 'realize': 0.32; 'list': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'skip:& 10': 0.37; 'received:209': 0.38; 'feedback': 0.38; 'skip:p 20': 0.38; 'thank': 0.38; 'takes': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'your': 0.60; 'sample': 0.63; 'score': 0.76; 'counts': 0.81; 'algorithm,': 0.84; 'time..': 0.91; 'average': 0.93; 'rating': 0.93
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to; bh=YeUeEdGeMD2hKL6oHJBeLBJNIRDpJye1S8TRnzOUHgw=; b=EvEQT5fEVW9prG+/hbzwNFH1HGWlugMqT2Q6x6Ecfohfpe3TE344KmDziGPvtRSmwq ESed7avGd0rWCRKdhY4Vnl5K7ZkmeH/pLs7RLrzLwOG1VvJgFp8rRqYJFBfC01KFHrpL gWMJLBR3dKI+/hXv1hWwVNB1uaYwfGgNQxRg2LVJSmda/G2jOiKhd2LsS3+wZCciOu/N AyjlI77/Gil7H0BYjvpfISvGw1Hg86cFFi004bvXAHQ7Uma9TKPo79jpo5I5MUbvNWmz +Z3wVAIqbT3PzWvNcKF0QEzXEnfiuKaz8DmE4e+zNn4PJejxmQTYTGaFL08SwNKIqIEL cDSA==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=YeUeEdGeMD2hKL6oHJBeLBJNIRDpJye1S8TRnzOUHgw=; b=IDRaUbUaIvbrFbGOHUlnMYTQHEO0txVpJPR7uHCgEtV/gQhqRyH1PWINrw/W5xQOdZ TYRFbyhwlJcCx1efD8i5ji1VTK8BrsdCDNlvPXkvV0bwXSmT9S421kZAD3QOo4+oYP4g F8GgEi4EMPUT9P3gMGf0RxcP9aF4jYKe0kWE37P/y2FwTEZJj5apKB1sZpbbF1X/pzhx 57Su1/i+Hikp1piiWHOiD+D4ZBvn8imBKiiFR2Ncis/WDQMjdPY6B01nUfvctleSF7L1 DGOnzLh7lFexPN6dRj4M3YBg1IKXiVIYuhYxD9OT502gyB+a1WQx/nITnW//qKlrQDpC SKoQ==
X-Gm-Message-State AOPr4FV0Qfr5zRj2hDKi9LTf2cS8HDIO/fGJbSaPqWFR7kMW8GfON1yoofK/+Y+2Pkc0z9dtBV2sw4TFLOknbQ==
X-Received by 10.112.49.50 with SMTP id r18mr5410125lbn.65.1460601433846; Wed, 13 Apr 2016 19:37:13 -0700 (PDT)
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CAO1D73EFoLoJm=4shNfgEsJinGHrM82J_BsTRMnm7XX4tW1h+A@mail.gmail.com>
Xref csiph.com comp.lang.python:106969

Show key headers only | View raw


Hi all,

I'm looking for feedback on the below vote weighting algorithm which
includes sample input. This is written in Python3.

def weight(votes):
    """
    Takes a list of tuples in the form of '(vote %, weight)' where vote %
is the
    rating that a user gave and weight is the number of votes it counts as.

    Returns the average score based on votes and vote weight.
    """

    sum_of_votes = 0

    num_of_votes = 0

    for vote, weight in votes:

        sum_of_votes += vote * weight
        num_of_votes += weight

    score = sum_of_votes/num_of_votes

    return score


if __name__ == '__main__':

    votes = [(72, 4), (96, 3), (48, 2), (53, 1), (26, 4), (31, 3), (68, 2),
(91, 1)]

    print(weight(votes))


Specifically, I'm wondering if this is a good algorithm for weighted
voting. Essentially a vote is weighted by the number of votes it counts as.
I realize that this is an extremely simple algorithm, but I was wondering
if anyone had suggestions on how to improve it. Thank you for your time.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Looking for feedback on weighted voting algorithm justin walters <walters.justin01@gmail.com> - 2016-04-13 19:37 -0700

csiph-web