> For the complete documentation index, see [llms.txt](https://docs.sdv.dev/sdmetrics/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sdv.dev/sdmetrics/data-metrics/metrics-in-beta/data-likelihood/bnloglikelihood.md).

# BNLogLikelihood

Data Likelihood describes a set of metrics that calculate the likelihood of the synthetic data belonging to the real data. This metric uses the log of Bayesian Network to make this calculation.

## Data Compatibility

* **Categorical**: This metric is meant for discrete, categorical data
* **Boolean**: This metric works on boolean data

This metric ignores any incompatible column types.

{% hint style="warning" %}
This metric does not accept missing values
{% endhint %}

## Score

**(highest) 1.0**: According to the algorithm, the synthetic data has the highest possible likelihood of belonging to the real data

**(lowest) -∞**: According to the algorithm used, the synthetic data has the lowest possible likelihood of belonging to the real data

{% hint style="danger" %}
**There are multiple interpretations of the score.** A high score can indicates high synthetic data quality as well as low privacy. A low score can indicate low synthetic data quality as well as high privacy.&#x20;
{% endhint %}

## How does it work?

This metric uses a Bayesian Network \[1] from pomegranate \[2] to learn the distribution of the real data. The model learns to produce a likelihood estimate for every row ranging from 0 to 1, where 0 means the row is likely not part of the data and 1 means that it is.

We apply the model to all the synthetic data. This metric takes the natural log of every score, which transform the score from the \[0, 1] range to the \[-∞, 1] range. The final score is the average of all scores.&#x20;

## Usage

{% hint style="warning" %}
You will need to install the `pomegranate` library in order to use this metric

```
pip install pomegranate
```

{% endhint %}

Access this metric from the `single_table` module and use the `compute` method.

```python
from sdmetrics.single_table import BNLogLikelihood

BNLogLikelihood.compute(
    real_data=real_table,
    synthetic_data=synthetic_table
)
```

**Parameters**

* (required) `real_data`: A pandas.DataFrame containing the real data
* (required) `synthetic_data`: A pandas.DataFrame containing the same columns of synthetic data
* `metadata`: A metadata dictionary describing the columns (see [Metadata](/sdmetrics/getting-started/metadata.md))
* `structure`:  The BayesianNetwork structure to use when fitting to the real data. If not passed, learn it from the data using the Chow-Liu algorithm \[3].

## FAQs

{% hint style="info" %}
**This metric is in Beta.** Be careful when using the metric and interpreting its score.

* The score heavily depends on algorithm used to model the data. If the overall distribution of the real data cannot be learned well, then the likelihood estimates of the synthetic data may not be valid.
* There are multiple interpretations for this metric. (See the [Score](#score) section above.) Of course, this is heavily dependent on how well we trust the algorithm to model the real data.
  {% endhint %}

## References

\[1] <https://en.wikipedia.org/wiki/Bayesian_network>

\[2] <https://pomegranate.readthedocs.io/en/docs/index.html>

\[3] <https://en.wikipedia.org/wiki/Chow%E2%80%93Liu_tree>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.sdv.dev/sdmetrics/data-metrics/metrics-in-beta/data-likelihood/bnloglikelihood.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
