Methods

These convenience classes implement the covariance-based Local Resampler methods used in the README examples.

class synloc.LocalCov(data, K=30, normalize=True, clipping=True, n_jobs=-1, Args_NearestNeighbors={}, random_state=None)[source]

This is a method for clusterResampler class to create synthetic samples from the multivariate normal distribution with the estimated covariance matrix.

Parameters:
  • data (pandas.DataFrame) – Original data set to be synthesized

  • K (int, optional) – The number of the nearest neighbors used to create synthetic samples, defaults to 30

  • normalize (bool, optional) – Normalize sample before defining clusters, defaults to True

  • clipping (bool, optional) – trim values greater (smaller) than the maximum (minimum) for each variable, defaults to True

  • n_jobs (int, optional) – The number of jobs to run in parallel, defaults to -1

  • Args_NearestNeighbors (dict, optional) – NearestNeighbors function arguments can be specified if needed. See scikit-learn.org/stable/modules/generated/sklearn.neighbors.NearestNeighbors.html , defaults to {}

  • random_state (int, optional) – Optional integer seed for anchor selection and NumPy-based draws.

static method(subsample)[source]

Estimates covariance matrix and draw samples from the estimated multivariate normal distribution.

Parameters:

subsample (pandas.DataFrame) – A subsample defined by the kNNResampler class.

Returns:

Synthetic values.

Return type:

numpy.darray

prepare_export(n_components=None, random_state=None)[source]

Select anchors and fit a fixed parameter-only export proposal.

n_components=None selects all anchors. A smaller positive count selects distinct anchors uniformly without replacement. Every selected neighbourhood is found in the full source data.

class synloc.clusterCov(data, n_clusters=8, size_min=None, normalize=True, clipping=True)[source]

clusterCov is a method for clusterResampler class to create synthetic values from the multivariate normal distribution with the covariance matrix estimated from the clusters.

Parameters:
  • data (pandas.DataFrame) – Original data set to be synthesized

  • n_clusters (int, optional) – The number of clusters, defaults to 8

  • size_min (int, optional) – Required minimum cluster size, defaults to None

  • normalize (bool, optional) – Normalize sample before defining clusters, defaults to True

  • clipping (bool, optional) – trim values greater (smaller) than the maximum (minimum) for each variable, defaults to True

property columns
property covariances_
disclosure_diagnostics()[source]

Return per-component diagnostics computed from the source rows.

One row per component, in the order of means_: count (source rows), rank (rank of the centred rows), constant_columns, and top1_share_<column>/top2_share_<column> (largest one and two values as shares of the component total; NaN for negative values or a zero total). The diagnostics are confidential, are not exported, apply no thresholds and do not establish privacy.

export_model(path)[source]

Write the fitted parameters to a versioned NPZ file.

fit_model()[source]

Fit raw-unit mixture parameters without generating synthetic records.

Normalization affects clustering only; means and covariances are in original units. The legacy fit() workflow remains unchanged.

property means_
method(cluster, size)[source]

Creating synthetic values from the estimated multivariate normal distribution.

Parameters:
  • cluster (pandas.DataFrame) – Cluster data

  • size (int) – Required number of synthetic observations. Size is equal to the number of observations in the cluster if not specified.

Returns:

Synthetic values

Return type:

pandas.DataFrame

sample(n, random_state=None)[source]

Sample fitted parameters only, without legacy source-bound clipping.

property weights_