A library aiding to create anonymizers (privacy preserving machine learning models) for the AnoMed competition platform.
Project description
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 fromtraining_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,
)
# 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="http://example.com/train",
tuning_data_url="http://example.com/tuning",
validation_data_url="http://example.com/validation",
utility_evaluation_url="http://example.com/utility",
model_loader=anon.unpickle_anonymizer,
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anomed_anonymizer-0.0.12.tar.gz.
File metadata
- Download URL: anomed_anonymizer-0.0.12.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8289cc8dc9783b0a1357f7fcf255bed950b88abcd1255c43a7001c82d559f76
|
|
| MD5 |
11aeeb7f8d9604fb70845a0257c746d9
|
|
| BLAKE2b-256 |
6afa52a940211c72b1825c2a1a356afbb7ed3bd2e0652f41db485d28c83b91b2
|
File details
Details for the file anomed_anonymizer-0.0.12-py3-none-any.whl.
File metadata
- Download URL: anomed_anonymizer-0.0.12-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3aff91ee2891c4d106590b134966d9723599a65fee59e7b77eac6d2cb650dab
|
|
| MD5 |
0ca38cee24d2cf26ddb496e7c0818316
|
|
| BLAKE2b-256 |
c7bf78c77037870404ea9539e51bdc816f11b80957070a579239d4b6cd959bd9
|