# Multi Table API

The Multi Table Diagnostic Report runs some basic checks on your synthetic data to give a general sense of the strengths and weakness of your synthetic data model.&#x20;

Use this report when you have multiple, connected tables of data.

## Usage

### Generating the report

#### DiagnosticReport()

Create your report object by importing it from the multi table reports module.

```python
from sdmetrics.reports.multi_table import DiagnosticReport

report = DiagnosticReport()
```

#### generate(real\_data, synthetic\_data, metadata)

Generate your report by passing in the data and metadata.

* (required) `real_data`: A dictionary mapping the name of each table to a pandas.DataFrame containing the real data for that table
* (required) `synthetic_data`: A dictionary mapping the name of each table to a pandas.DataFrame containing the synthetic data for that table
* (required) `metadata`: A dictionary describing the format, types of data and relationship between the tables. See [Multi Table Metadata](https://docs.sdv.dev/sdmetrics/getting-started/metadata/multi-table-metadata) for more details.
* `verbose`: A boolean describing whether or not to print the report progress and results. Defaults to `True`. Set this to `False` to run the report silently.

```python
report.generate(real_data, synthetic_data, metadata)
```

You'll see a progress bar as the report is generated. Once completed, the diagnostic results are printed out.

```
Generating report ...

(1/3) Evaluating Data Validity: |██████████| 15/15 [00:00<00:00, 603.69it/s]|
Data Validity Score: 100.0%

(2/3) Evaluating Data Structure: |██████████| 2/2 [00:00<00:00, 151.49it/s]|
Data Structure Score: 100.0%

(3/3) Evaluating Relationship Validity: |██████████| 1/1 [00:00<00:00, 68.51it/s]|
Relationship Validity Score: 100.0%

Overall Score (Average): 100.0%
```

### Getting & explaining the results

#### get\_score()

Use this method at any point to retrieve the overall score.&#x20;

Returns: A floating point value between 0 and 1 that summarizes the quality of your synthetic data.

```python
report.get_score()
```

```python
1.0
```

{% hint style="success" %}
:100: **The score should be 100% or very close to it.** The diagnostic report checks for basic data validity and data structure issues. If you want to create synthetic data that looks and feels similar to the real data, you should expect to score to be perfect. If you are using any of the default SDV synthesizers, the score should always be 1.0.
{% endhint %}

#### get\_properties()

Use this method at any point to retrieve each property that the report evaluated

Returns: A dictionary that lists each property name and its associated score

```python
report.get_properties()
```

```python
{
  'Data Validity': 1.0,
  'Data Structure': 1.0,
  'Relationship Validity': 1.0
}
```

#### get\_details(property\_name)

Use this method to get more details about a particular property.

* (required) `property_name`: A string with the name of the property. One of: `'Data Validity'`, `'Data Structure'` or `'Relationship Validity'`.
* `table_name`: A string with the name of the table. If provided, you'll receive filtered results for the table.

Returns: A pandas.DataFrame object that returns more details about the property for the given table

For example, the details for `'Data Validity'` shows the name of each individual column, the metric that was used to compute it and the overall score for that column.&#x20;

```python
report.get_details(
    property_name='Data Validity',
    table_name='users'
)
```

```python
Table        Column        Metric                 Score
users        user_id       KeyUniqueness          1.0   
users        age           BoundaryAdherence      1.0     
users        height        BoundaryAhderence      1.0            
users        card_type     CategoryAdherence      1.0
...
```

### Visualizing the report

You can visualize the properties and use the SDMetrics utilities to visualize the raw data too.

#### get\_visualization(property\_name, table\_name)

Use this method to visualize the details about a property.&#x20;

* (required) `property_name`: A string with the name of the property. Currently, `'Data Validity'` or `'Relationship Validity'` are supported.
* (required) `table_name`: A string with the name of the table

Returns: A [plotly.Figure](https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html) object

For example, the `'Data Validity'` property visualizes the score for every column as well as the metric used to compute it.

```python
fig = report.get_visualization(
    property_name='Data Validity',
    table_name='users'
)
fig.show()
```

{% hint style="success" %}
**Other visualizations are available!** Use the [SDMetrics Visualization Utilities](https://docs.sdv.dev/sdmetrics/getting-started/visualization-utilities) to get more insights into your data.\
\
**Tip!** All visualizations returned in this report are interactive. If you're using an iPython notebook, you can zoom, pan, toggle legends and take screenshots.
{% endhint %}

### Saving & loading the report

You can save your report if you want to share or access it in the future.

#### save(filepath)

Save the Python report object

* (required) `filepath`: The name of file to save the object. This must end with `.pkl`

```python
report.save(filepath='results/diagnostic_report.pkl')
```

{% hint style="warning" %}
The report does not save the full real and synthetic datasets, but it does save the metadata along with the score for each property, breakdown and metric.

The score information may still leak sensitive details about your real data. Use caution when deciding where to store the report and who to share it with.
{% endhint %}

#### DiagnosticReport.load(filepath)

Load the report from the file

* (required) `filepath`: The name of the file where the report is stored

Returns: A `DiagnosticReport` object.

```python
from sdmetrics.reports.multi_table import DiagnosticReport

report = DiagnosticReport.load('results/diagnostic_report.pkl')
```

## FAQs

<details>

<summary>What is the best way to see the visualizations? Can I save them?</summary>

This report returns all visualizations as [plotly.Figure](https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html) object, which are integrated with most iPython notebooks (eg. Colab, Jupyter).

**Tip!** You can interact with the visualizations when you're viewing them in a notebook. You can zoom, pan and take screenshots.

It's also possible to programmatically save a static image export. See the [Plotly Guide](https://plotly.com/python/static-image-export/) for more details.

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sdv.dev/sdmetrics/data-metrics/diagnostic/diagnostic-report/multi-table-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
