Skip to main content

Monadic election precinct matcher for gerrymandering data collection and research at MGGG

Project description

(monadic) Precinct Matcher

Matching election data to shapefiles is hard. It is usually context-dependent and implemented on a project-by-project basis. It also sometimes involves some manual labor. This attempts to make life easier for everyone who has to deal with precinct matching.

Install

pip install pmatcher

Benchmarks (on real data)

VEST releases its precincts with VTD codes and county FIPS codes. To validate this approach, I ran the matcher on known, good data.

Results (in % accuracy):

Exact match 0.9444831591173054
Insensitive match 0.9444831591173054
Insensitive normalized match 0.9932636469221835
Aggressive insensitive normalized match 0.9983739837398374

Implemented Methods

  • matcher.default() Applies exact, insensitive, normalized, and weighted_manual in that order. All batteries included!

  • matcher.exact() Matches exact strings.

  • matcher.insensitive() Matches strings (case-insensitive).

  • matcher.insensitive_normalized() Matches strings with special characters removed (e.g.(), #, -).

  • matcher.weighted_manual() Uses a weighted levenshtein algorithm. First looks for token-distance, followed by token word distance for tiebreaking.

Saving and loading progress

  • matcher.save_progress("progress.json") Saves progress/mapping to a json file.

  • matcher.load_progress("progress.json") Loads progress/mapping from a json file.

Example usage

from pmatcher import PrecinctMatcher
matcher = PrecinctMatcher(list_1, list_2)
mapping = matcher.default()
from pmatcher import PrecinctMatcher
matcher = PrecinctMatcher(list_1, list_2)
matcher.exact()
matcher.insensitive()
matcher.insensitive_normalized()
matcher.insensitive_normalized(aggressive=True)
mapping = matcher.weighted_manual()

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

pmatcher-0.1.14.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

pmatcher-0.1.14-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pmatcher-0.1.14.tar.gz.

File metadata

  • Download URL: pmatcher-0.1.14.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.6 Linux/5.11.0-7620-generic

File hashes

Hashes for pmatcher-0.1.14.tar.gz
Algorithm Hash digest
SHA256 b84fbcdb07727b84bb66c01f02641d2957a3272bee4e5e91ca8df27f87c40402
MD5 3ac112fcb0779940e3e910b63d196841
BLAKE2b-256 fd995268b9e140b953ecf1c2bc2061f1f9877d61bc2734ae0d1927ad60bf70bb

See more details on using hashes here.

File details

Details for the file pmatcher-0.1.14-py3-none-any.whl.

File metadata

  • Download URL: pmatcher-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.6 Linux/5.11.0-7620-generic

File hashes

Hashes for pmatcher-0.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 a48ae22b11ab78255b6e63288f1e4ad15989d1584beff0b47aeb88a0aff21a9b
MD5 4fe1c8d110064f8c1f75d728cd6fc791
BLAKE2b-256 e5502da9b7d9a63fcfccea96713572e21beb59daecf4509c46ed80218959ec11

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page