Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add testing for JSD metrics #100

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions tests/metrics/test_jsd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import numpy as np
import pandas as pd
import pytest

from sdgx.metrics.column.jsd import JSD

# 创建测试数据
real_data_discrete = pd.DataFrame(
{
"col1": ["a", "b", "c", "d", "e"],
"col2": ["a", "b", "b", "b", "e"],
}
)

synthetic_data_discrete = pd.DataFrame(
{
"col1": ["a", "c", "d", "b", "b"],
"col2": ["a", "c", "a", "a", "e"],
}
)

real_data_cotinuous = pd.DataFrame(
{
"col1": [1, 1, 2, 2, 3],
"col2": [4, 4, 5, 5, 6],
}
)

synthetic_data_cotinuous = pd.DataFrame(
{
"col1": [1, 2, 2, 3, 3],
"col2": [4, 5, 5, 6, 6],
}
)

# 创建 JSD 实例
jsd_instance = JSD()

MooooCat marked this conversation as resolved.
Show resolved Hide resolved

def test_jsd_discrete():
cols = ["col1", "col2"]
result = jsd_instance.calculate(
real_data_discrete, synthetic_data_discrete, cols, discrete=True
)
result1 = jsd_instance.calculate(real_data_discrete, real_data_discrete, cols, discrete=True)
result2 = jsd_instance.calculate(
synthetic_data_discrete, real_data_discrete, cols, discrete=True
)

assert result >= 0
assert result <= 1
assert result1 == 0
assert result2 == result


def test_jsd_continuous():
cols = ["col1"]
result = jsd_instance.calculate(
real_data_cotinuous, synthetic_data_cotinuous, cols, discrete=False
)
result1 = jsd_instance.calculate(real_data_cotinuous, real_data_cotinuous, cols, discrete=False)
result2 = jsd_instance.calculate(
synthetic_data_cotinuous, real_data_cotinuous, cols, discrete=False
)

assert result >= 0
assert result <= 1
assert result1 == 0
assert result2 == result
Loading