Having performed various individual evaluations across statistical fidelity, machine learning utility, and privacy, the next step is to consolidate these findings into a structured and interpretable format. Manually compiling scores, charts, and interpretations for every synthetic dataset can be tedious and prone to inconsistency. Fortunately, specialized libraries exist to streamline this process, allowing you to generate standardized quality reports programmatically.
This practice section demonstrates how to use the SDMetrics
library to generate a concise quality report snippet. SDMetrics
offers a convenient way to compute multiple metrics across different quality dimensions and present them in a structured manner. While we focus on a snippet here, remember that a comprehensive report, as discussed earlier, would involve a broader selection of metrics tailored to your specific goals, detailed visualizations, and thorough interpretation.
Let's assume you have your real dataset (real_data
) and a synthetic dataset (synthetic_data
) loaded as Pandas DataFrames.
import pandas as pd
from sdmetrics import گزارش 품질 보고서
from sdmetrics.reports.utils import display_metadata
from sdmetrics.demos import load_single_table_demo
# Load demo data for reproducibility
real_data, synthetic_data, metadata = load_single_table_demo()
# Display the metadata structure (optional, for understanding)
# display_metadata(metadata)
The metadata
dictionary is important. It tells SDMetrics
about the data types (numerical, categorical, datetime, etc.) and any primary keys or constraints. Accurate metadata leads to more meaningful metric calculations. For the demo data, this is pre-loaded. For your own data, you would typically define this dictionary manually or use detection utilities.
Now, let's create a quality report object. SDMetrics
provides different report classes. The QualityReport
class offers a broad overview covering multiple aspects.
# Initialize the quality report object
report = QualityReport()
# Compute metrics and generate the report
# This step performs calculations based on the provided data and metadata
report.generate(real_data, synthetic_data, metadata)
# The report object now contains computed scores and properties.
The generate
method runs a default set of metrics relevant to single-table data. These typically include measures of column-wise distributional similarity, correlation similarity, and potentially some basic synthesis detection checks.
You can inspect the overall quality score, which aggregates individual metric scores:
# Get the overall quality score (0 to 1, higher is better)
overall_score = report.get_score()
print(f"Overall Quality Score: {overall_score:.3f}")
To understand what contributes to this score, you can examine the scores for individual properties (like column shapes, column pair trends):
# Get scores for different properties
properties = report.get_properties()
print("\nProperties Breakdown:")
print(properties)
This might produce output like:
Properties Breakdown:
Property Score
0 Column Shapes 0.851
1 Column Pair Trends 0.789
These properties aggregate results from multiple underlying metrics. For instance, 'Column Shapes' often involves comparing marginal distributions using tests like Kolmogorov-Smirnov (KS) for numerical data or Chi-Squared for categorical data. 'Column Pair Trends' usually involves comparing correlation matrices or pairwise mutual information.
For more detail, you can access the results of every individual metric computed:
# Get detailed results for each metric computed
details = report.get_details(property_name='Column Shapes')
print("\nDetails for 'Column Shapes':")
print(details)
This provides a granular view, showing which columns performed well or poorly in terms of distributional similarity.
Details for 'Column Shapes':
Column Metric Score Error
0 student_id KSComplement 0.920 NaN
1 start_date KSComplement 0.885 NaN
2 end_date KSComplement 0.877 NaN
3 tuition KSComplement 0.721 NaN
4 grade TVComplement 0.850 NaN
...
Here, KSComplement
(1 - KS statistic) measures numerical distribution similarity, and TVComplement
(1 - Total Variation Distance) measures categorical distribution similarity. Higher scores (closer to 1) indicate better fidelity for that specific column's distribution.
While SDMetrics
provides some basic plotting capabilities within its report structure (especially in environments like Jupyter), you can also extract the scores and use standard plotting libraries like Plotly for customized visualizations as discussed in the "Visualizing Evaluation Results Effectively" section. For example, let's visualize the property scores using Plotly.
Bar chart displaying the aggregated scores for 'Column Shapes' and 'Column Pair Trends', providing a quick visual summary of the report's main findings.
Generating such report snippets programmatically is invaluable for:
Remember, libraries like SDMetrics
offer defaults but are also customizable. You can select specific metrics, add new ones, or even create entirely custom report structures to fit your evaluation pipeline. This example provides a starting point for integrating automated reporting into your synthetic data quality assessment workflow, translating raw metric outputs into digestible insights.
© 2025 ApX Machine Learning