Skip to content

Commit 7719f83

Browse files
authored
fix: handle edge case of DCR share being 0 (#189)
1 parent 13a0b8a commit 7719f83

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

mostlyai/qa/_distances.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,10 @@ def calculate_distances(
112112
g_dcr_share = calculate_dcr_share(g_dcr_syn_trn, g_dcr_syn_hol)
113113
g_nndr_ratio = calculate_nndr_ratio(g_nndr_syn_trn, g_nndr_syn_hol)
114114
if len(columns) == ori_embeds.shape[1]:
115-
_LOG.info(f"DCR Share: {g_dcr_share:.1%}, NNDR Ratio: {g_nndr_ratio:.3f} - ALL columns")
115+
suffix = "ALL columns"
116116
else:
117-
_LOG.info(
118-
f"DCR Share: {g_dcr_share:.1%}, NNDR Ratio: {g_nndr_ratio:.3f} - {len(columns)} columns [{columns}]"
119-
)
117+
suffix = f"{len(columns)} columns [{columns}]"
118+
_LOG.info(f"DCR Share: {g_dcr_share:.1%}, NNDR Ratio: {g_nndr_ratio:.3f} - {suffix}")
120119
if g_dcr_share > dcr_share:
121120
# keep results if DCR share is MAX
122121
dcr_share = g_dcr_share
@@ -125,8 +124,6 @@ def calculate_distances(
125124
dcr_syn_hol, nndr_syn_hol = g_dcr_syn_hol, g_nndr_syn_hol
126125
dcr_trn_hol, nndr_trn_hol = g_dcr_trn_hol, g_nndr_trn_hol
127126
_LOG.info(f"DCR Share: {dcr_share:.1%}, NNDR Ratio: {nndr_ratio:.3f} - FINAL")
128-
_LOG.info(f"share of dcr_syn_trn < dcr_syn_hol: {np.mean(dcr_syn_trn < dcr_syn_hol):.1%}")
129-
_LOG.info(f"share of dcr_syn_trn > dcr_syn_hol: {np.mean(dcr_syn_trn > dcr_syn_hol):.1%}")
130127

131128
return {
132129
"dcr_syn_trn": dcr_syn_trn,

0 commit comments

Comments
 (0)