SafeSVC#

An example Python Notebook is available Here

Privacy protected Support Vector Classifier.

class sacroml.safemodel.classifiers.safesvc.SafeSVC(C: float = 1.0, gamma: str | float = 'scale', dhat: int = 1000, eps: float = 10, **kwargs: dict)[source]#

Privacy protected Support Vector Classifier.

Methods

additional_checks(curr_separate, saved_separate)

SVC specific checks.

examine_seperate_items(curr_vals, saved_vals)

Check model-specific items exist in both current and saved copies.

fit(train_features, train_labels)

Fit model and store model dict.

get_current_and_saved_models()

Copy self.__dict__ and split into dicts for current and saved versions.

get_params([deep])

Get a dictionary of parameter values restricted to those expected.

k_hat_svm(x[, y])

Define the version which is sent to sklearn.svm.

phi_hat(input_vector)

Project a single feature.

phi_hat_multi(input_features)

Compute feature space for a matrix of inputs.

posthoc_check()

Check whether model has been interfered with since fit() was last run.

predict(test_features)

Return the predictions.

predict_proba(test_features)

Return the predictive probabilities.

preliminary_check([verbose, apply_constraints])

Check whether current model parameters violate the safe rules.

request_release(path, ext[, target])

Save model and create a report for the TRE output checkers.

run_attack(target, attack_name[, output_dir])

Run a specified attack on the trained model and save report to file.

save([name])

Write model to file in appropriate format.

set_params(**kwargs)

Set params.

__init__(C: float = 1.0, gamma: str | float = 'scale', dhat: int = 1000, eps: float = 10, **kwargs: dict) None[source]#

Initialise a differentially private SVC.

additional_checks(curr_separate: dict, saved_separate: dict) tuple[str, str][source]#

SVC specific checks.

examine_seperate_items(curr_vals: dict, saved_vals: dict) tuple[str, bool]#

Check model-specific items exist in both current and saved copies.

fit(train_features: ndarray, train_labels: ndarray) None[source]#

Fit model and store model dict.

get_current_and_saved_models() tuple[dict, dict]#

Copy self.__dict__ and split into dicts for current and saved versions.

get_params(deep: bool = True) dict#

Get a dictionary of parameter values restricted to those expected.

k_hat_svm(x: ndarray, y: ndarray | None = None) ndarray#

Define the version which is sent to sklearn.svm.

phi_hat(input_vector: ndarray) ndarray#

Project a single feature.

phi_hat_multi(input_features: ndarray) ndarray#

Compute feature space for a matrix of inputs.

posthoc_check() tuple[str, bool]#

Check whether model has been interfered with since fit() was last run.

predict(test_features: ndarray) ndarray#

Return the predictions.

predict_proba(test_features: ndarray) ndarray#

Return the predictive probabilities.

preliminary_check(verbose: bool = True, apply_constraints: bool = False) tuple[str, bool]#

Check whether current model parameters violate the safe rules.

Optionally fixes violations.

Parameters:
verbosebool

A boolean value to determine increased output level.

apply_constraintsbool

A boolean to determine whether identified constraints are to be upheld and applied.

Returns:
msgstring

A message string.

disclosivebool

A boolean value indicating whether the model is potentially disclosive.

request_release(path: str, ext: str, target: Target = None) None#

Save model and create a report for the TRE output checkers.

Parameters:
pathstring

Path to save the outputs.

extstr

File extension defining the model saved format, e.g., “pkl” or “sav”.

targetattacks.target.Target

Contains model and dataset information.

Notes

If target is not null, then worst case MIA and attribute inference attacks are called via run_attack.

run_attack(target: Target, attack_name: str, output_dir: str = 'outputs_safemodel') dict#

Run a specified attack on the trained model and save report to file.

Parameters:
targetTarget

The target in the form of a Target object.

attack_namestr

Name of the attack to run.

output_dirstr

Name of the directory to store JSON and PDF reports.

Returns:
dict

Metadata results.

save(name: str = 'undefined') None#

Write model to file in appropriate format.

Note this is overloaded in SafeKerasClassifer to deal with tensorflow specifics.

Parameters:
namestring

The name of the file to save.

Notes

Optimizer is deliberately excluded to prevent possible restart to training and thus possible back door into attacks.

set_params(**kwargs: dict) None#

Set params.

examine_seperately_items: list[str]#
filename: str#
ignore_items: list[str]#
model_load_file: str#
model_save_file: str#
model_type: str#
researcher: str#
timestamp: str#