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.
from synthesized.insight.metrics import EarthMoversDistance df_synth = synthesizer.synthesize(1000) emd = EarthMoversDistance() 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.)
CramersV: calculates the Cramer’s V value. This measures the strength of the association between two categorical attributes.
CategoricalLogisticR2: calculates McFadden’s R squared. This measures the association between a categorical and continuous attribute.
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.
from synthesized.insight.metrics import CramersV df_synth = synthesizer.synthesize(1009) cramers = CramersV() # calculate association on original data cramers(df_original["categorical_column_a"], df_original["categorical_column_b"]) # calculate association on synthetic data 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
Assessor requires a
DataFrameMeta class extracted from the
original data-frame, and can be created with these commands:
from synthesized import MetaExtractor from synthesized.testing import Assessor df_meta = MetaExtractor.extract(df) assessor = Assessor(df_meta)
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(
show_distributions plots all marginal distributions in two datasets,
Example plot for
assessor.show_emd_distances() plot for each column the
EarthMoversDistance difference between both datasets:
Example plot of
The user can also plot the difference of any other univariate metric (let’s call it
MyDistanceMetric) with the
Assessor class is also able to plot different joint distributions and correlation distances in two
show_second_order_metric_matricesplots the matrices of all combinations of columns, with the value of the specified metric between each pair columns in the corresponding cell.
show_second_order_metric_distancesplots 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;
assessor.show_kendall_tau_distances(df_orig, df_synth) assessor.show_spearman_rho_matrices(df_orig, df_synth)
Example plot of
Example plot of