Skip to main content

A library aiding to create anonymizers (privacy preserving machine learning models) for the AnoMed competition platform.

Project description

Code style: black pipeline status coverage

Anonymizer

A library aiding to create anonymizers (privacy preserving machine learning models) for the AnoMed competition platform.

Usage Example

The following example will create a Falcon-based web app that encapsulates an anonymizer for an example challenge (which serves the famous iris dataset). The encapsulated anonymizer is differentially private Gaussian naive Bayes classifier, which aims to solve a 3-class classification problem.

The web app offers these routes (some may have query parameters not mentioned here):

  • [GET] / (This displays an "alive message".)
  • [POST] /fit (This invokes fitting the Gaussian naive based classifier; the web app will pull the training data from training_data_url.)
  • [POST] /evaluate (This invokes an intermediate, or final evaluation of the classifier.)
  • [POST] /predict (This offers a way to use the fitted anonymizer to predict the target values for arbitrary, but compatible, feature arrays.)
import anomed_anonymizer as anon
import numpy as np
from diffprivlib.models import GaussianNB

lower_bounds = 4 * [0.0]
upper_bounds = [10.0, 5.0, 10.0, 5.0]
estimator = GaussianNB(
    bounds=(lower_bounds, upper_bounds),
    priors=3 * [1.0 / 3.0],
)


def input_array_validator(feature_array: np.ndarray) -> None:
    if feature_array.shape[1] != 4 or len(feature_array.shape) != 2:
        raise ValueError("Feature array needs to have shape (n_samples, 4).")
    if feature_array.dtype != np.float_:
        raise ValueError("Feature array must be an array of floats.")


example_anon = anon.WrappedAnonymizer(
    anonymizer=estimator,
    serializer=anon.pickle_anonymizer,
    feature_array_validator=input_array_validator,
)

hostname = "example.com"

# This is what GUnicorn expects
application = anon.supervised_learning_anonymizer_server_factory(
    anonymizer_identifier="example_anonymizer",
    anonymizer_obj=example_anon,
    model_filepath="anonymizer.pkl",
    default_batch_size=64,
    training_data_url=f"http://{hostname}/data/anonymizer/training",
    tuning_data_url=f"http://{hostname}/data/anonymizer/tuning",
    validation_data_url=f"http://{hostname}/data/anonymizer/training",
    utility_evaluation_url=f"http://{hostname}/utility/anonymizer",
    model_loader=anon.unpickle_anonymizer,
)

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

anomed_anonymizer-0.0.19.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anomed_anonymizer-0.0.19-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file anomed_anonymizer-0.0.19.tar.gz.

File metadata

  • Download URL: anomed_anonymizer-0.0.19.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for anomed_anonymizer-0.0.19.tar.gz
Algorithm Hash digest
SHA256 03d44023ce93144b29be6463da2ef3ce77f4a1b9ec21c7f6bf9252cc834c8b9e
MD5 991829d21b060f73df6c656196cf4d21
BLAKE2b-256 f03c372c35f77839df34fd981ae7fa0f99128aca02cddbd579236dd79c3c6861

See more details on using hashes here.

File details

Details for the file anomed_anonymizer-0.0.19-py3-none-any.whl.

File metadata

File hashes

Hashes for anomed_anonymizer-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 53f2fd78877c57380c6c4c456f1e4ca63beaee650afc1d3dff357e4d12b15f18
MD5 cc87ea0187e8b32d68ec4ba8e6aab3a6
BLAKE2b-256 224b1343a065f48923a6cc68a8cf2b58c0e61caf7c4f78b55d02189ee21e2438

See more details on using hashes here.

Supported by

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