A variety of statistical metrics and techniques can be used to compare the original and synthetic data distributions.
These can be used to assess the synthetic data and its statistical resemblance to the original data. Each of these
metrics are available in
The distributions of each column in the original and synthesized dataset (of both continuous and categorical attributes) are compared using univariate statistical distance metrics. For each attribute in the data, these provide a comparison of the marginal probability distributions of the original and synthetic data. The following metrics are available:
Both of these distances vary between 0.0 and 1.0, where a value of 0.0 occurs when the original and synthetic data have exactly identical distributions. These metrics can be applied to compare the individual attributes of the synthetic and original data.
In : from synthesized.insight.metrics import EarthMoversDistance In : df_synth = synthesizer.synthesize(1000) In : emd = EarthMoversDistance() In : emd(df_original['categorical_column'], df_synth['categorical_column'])
Beyond univariate measures that look at single attributes in isolation, correlations and associations between each column can also be measured and compared between the synthetic and original datasets. Several metrics are used depending on whether the attributes to compare are categorical or continuous:
KendallTauCorrelation: calculates the Kendell-Tau coefficient. This measures the correlation between two ordinal continuous attributes. (Note: this assumes the two variables have a monotonic relationship.)
SpearmanRhoCorrelation: calculates Spearman’s rank correlation coefficient. This measures the association between two ordinal continuous attributes. (Note: this assumes the two variables have a monotonic relationship.)
Each of these metrics can be calculated on the original and synthetic data, and then compared to determine their statistical similarity.
In : from synthesized.insight.metrics import CramersV In : df_synth = synthesizer.synthesize(1009) In : cramers = CramersV() # calculate association on original data In : cramers(df_original["categorical_column_a"], df_original["categorical_column_b"]) # calculate association on synthetic data In : cramers(df_synth["categorical_column_a"], df_synth["categorical_column_b"])
These metrics check the input data to ensure it is categorical or continuous, depending on the assumptions of the
metric. If the data is of the incorrect type they will return
Alternatively, the evaluation metrics can be automatically calculated and visualized for the synthetic and original
data sets using the
synthesized.testing.Assessor requires a
synthesized.metadata.DataFrameMeta class extracted from the
original data-frame, and can be created with these commands:
In : from synthesized import MetaExtractor In : from synthesized.testing import Assessor In : df_meta = MetaExtractor.extract(df) In : assessor = Assessor(df_meta)
synthesized.testing.Assessor, it can be used to compare marginal distributions, joint distributions,
and classification metrics between two data-frames, usually the original and generated data-frames(
Comparing Marginal Distributions#
synthesized.testing.Assessor.show_distributions() plots all marginal distributions in two datasets,
In : assessor.show_distributions(df_orig, df_synth)
assessor.show_emd_distances() plot for each column the
EarthMoversDistance difference between both datasets:
In : assessor.show_ks_distances(df_orig, df_synth)
The user can also plot the difference of any other univariate metric (let’s call it
MyDistanceMetric) with the
In : assessor.show_first_order_metric_distances(MyDistanceMetric())
Comparing Joint Distributions#
Assessor class is also able to plot different joint distributions and correlation distances in two
show_second_[metric]_matrices) plots the matrices of all combinations of columns, with the value of the specified metric between each pair columns in the corresponding cell.
show_second_[metric]_distances) plots the distance of the given metric for each pair of columns between both datasets.
Both functions are available for the four interaction metrics defined above. For example;
In : assessor.show_kendall_tau_distances(df_orig, df_synth) In : assessor.show_spearman_rho_matrices(df_orig, df_synth)