mlresearch.metrics.Authenticity

class mlresearch.metrics.Authenticity(metric='euclidean', n_jobs=None)[source]

Quantifies the rate by which a model generates new samples. In other words, this scorer assesses whether a sample is non-memorized.

This is an implementation of the metric proposed in [1].

Warning

This metric is not listed in the get_scorer_names function since it is following an unconventional structure.

Parameters:
metricstr or callable, default=’euclidean’

Metric to use for distance computation. Default is “euclidean”, which results in the standard Euclidean distance. See the documentation of scipy.spatial.distance and the metrics listed in distance_metrics for valid metric values.

If metric is a callable function, it takes two arrays representing 1D vectors as inputs and must return one value indicating the distance between those vectors. This works for Scipy’s metrics, but is less efficient than passing the metric name as a string.

n_jobsint, default=None

The number of parallel jobs to run for neighbors search. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.

References

[1]

Alaa, A., Van Breugel, B., Saveliev, E. S., & van der Schaar, M. (2022, June). How faithful is your synthetic data? sample-level metrics for evaluating and auditing generative models. In International Conference on Machine Learning (pp. 290-306). PMLR.

Attributes:
nn_estimator object

Validated k-nearest neighbours algorithm. Used to find the nearest neighbors of the synthetic and the original data using the original data as a reference.

distances_real_np.ndarray, shape (n_samples,)

Distance to the nearest neighbor for each sample in X_real.


fit(X_real)[source]

Compute statistics necessary to calculate Authenticity.

Parameters:
X_realarray-like or pd.DataFrame, shape (n_samples, n_features)

The real (original) dataset used to fit self.scorer_real.

Returns:
selfobject

Returns an instance of the class.

get_metadata_routing()

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:
routingMetadataRequest

A MetadataRequest encapsulating routing information.

score(X)[source]

Returns 1 if an observation is deemed authentic, 0 otherwise.

Parameters:
Xarray-like or pd.DataFrame, shape (n_samples, n_features)

Input data over which Authenticity will be calculated.

Returns:
scoresnp.ndarray, shape (n_samples,)

Authenticity scores.

set_fit_request(*, X_real: bool | None | str = '$UNCHANGED$') Authenticity

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.

New 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:
X_realstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED

Metadata routing for X_real parameter in fit.

Returns:
selfobject

The updated object.

set_score_request()

Placeholder to overwrite sklearn’s _BaseScorer.set_score_request function. It is not used and was raising a docstring error with scikit-learn v1.3.0.