SafeDecisionTree

An example Python Notebook is available Here

Privacy protected Decision Tree classifier.

class aisdc.safemodel.classifiers.safedecisiontreeclassifier.SafeDecisionTreeClassifier(**kwargs: Any)[source]

Privacy protected Decision Tree classifier.

Attributes:
feature_importances_

Return the feature importances.

Methods

additional_checks(curr_separate, saved_separate)

Decision Tree-specific checks.

apply(X[, check_input])

Return the index of the leaf that each sample is predicted as.

cost_complexity_pruning_path(X, y[, ...])

Compute the pruning path during Minimal Cost-Complexity Pruning.

decision_path(X[, check_input])

Return the decision path in the tree.

examine_seperate_items(curr_vals, saved_vals)

Comparison of more complex structures in the super class we just check these model-specific items exist in both current and saved copies.

fit(x, y)

Do fit and then store k-anonymity and model dict.

get_current_and_saved_models()

Makes a copy of self.__dict__ and splits it into dicts for the current and saved versions.

get_depth()

Return the depth of the decision tree.

get_metadata_routing()

Get metadata routing of this object.

get_n_leaves()

Return the number of leaves of the decision tree.

get_params([deep])

Gets dictionary of parameter values restricted to those expected by base classifier.

posthoc_check()

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

predict(X[, check_input])

Predict class or regression value for X.

predict_log_proba(X)

Predict class log-probabilities of the input samples X.

predict_proba(X[, check_input])

Predict class probabilities of the input samples X.

preliminary_check([verbose, apply_constraints])

Checks whether current model parameters violate the safe rules.

request_release(path, ext[, target])

Saves model to filename specified and creates a report for the TRE output checkers.

run_attack([target, attack_name, ...])

Runs a specified attack on the trained model and saves a report to file.

save([name])

Writes model to file in appropriate format.

score(X, y[, sample_weight])

Return the mean accuracy on the given test data and labels.

set_fit_request(*[, x])

Request metadata passed to the fit method.

set_params(**params)

Set the parameters of this estimator.

set_predict_proba_request(*[, check_input])

Request metadata passed to the predict_proba method.

set_predict_request(*[, check_input])

Request metadata passed to the predict method.

set_score_request(*[, sample_weight])

Request metadata passed to the score method.

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

Decision Tree-specific checks.

fit(x: ndarray, y: ndarray) None[source]

Do fit and then store k-anonymity and model dict.

set_fit_request(*, x: bool | None | str = '$UNCHANGED$') SafeDecisionTreeClassifier

Request metadata passed to the fit method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
xstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for x parameter in fit.

Returns:
selfobject

The updated object.

set_predict_proba_request(*, check_input: bool | None | str = '$UNCHANGED$') SafeDecisionTreeClassifier

Request metadata passed to the predict_proba method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict_proba if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict_proba.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
check_inputstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for check_input parameter in predict_proba.

Returns:
selfobject

The updated object.

set_predict_request(*, check_input: bool | None | str = '$UNCHANGED$') SafeDecisionTreeClassifier

Request metadata passed to the predict method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to predict if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to predict.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
check_inputstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for check_input parameter in predict.

Returns:
selfobject

The updated object.

set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') SafeDecisionTreeClassifier

Request metadata passed to the score method.

Note that this method is only relevant if enable_metadata_routing=True (see sklearn.set_config()). Please see User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to score if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to score.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Note

This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a Pipeline. Otherwise it has no effect.

Parameters:
sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for sample_weight parameter in score.

Returns:
selfobject

The updated object.

aisdc.safemodel.classifiers.safedecisiontreeclassifier.decision_tree_internal_trees_are_equal(tree1_tree: Any, tree2_tree: Any) tuple[bool, str][source]

Tests for equality of the internal structures in a sklearn.tree._tree e.g. the structure, feature and threshold in each internal node etc.

aisdc.safemodel.classifiers.safedecisiontreeclassifier.decision_trees_are_equal(tree1: DecisionTreeClassifier, tree2: DecisionTreeClassifier) tuple[bool, str][source]

Compares two estimators of type sklearn.tree e.g. two decisionTreeClassifiers.

aisdc.safemodel.classifiers.safedecisiontreeclassifier.get_tree_k_anonymity(thetree: DecisionTreeClassifier, X: Any) int[source]

Returns the smallest number of data items in any leaf.