optimize
This commit is contained in:
@@ -611,20 +611,31 @@ for gt_col in gt_columns:
|
||||
result_col = f'result.{base_name}'
|
||||
|
||||
if result_col in df.columns:
|
||||
# Convert to numeric, force invalid to NaN
|
||||
s1 = pd.to_numeric(df[gt_col], errors='coerce')
|
||||
s2 = pd.to_numeric(df[result_col], errors='coerce')
|
||||
# 1. Convert to numeric, forcing errors to NaN
|
||||
# 2. Explicitly cast to float to prevent Boolean subtraction errors
|
||||
s1 = pd.to_numeric(df[gt_col], errors='coerce').astype(float)
|
||||
s2 = pd.to_numeric(df[result_col], errors='coerce').astype(float)
|
||||
|
||||
# Calculate matches (abs difference <= 0.5)
|
||||
# Note: .sum() treats True as 1
|
||||
matches = (np.abs(s1 - s2) <= 0.5).sum()
|
||||
percentage = (matches / len(df)) * 100
|
||||
# We use .count() to find how many non-NaN values we have if you want
|
||||
# a more accurate percentage, or keep len(df) for the total row count.
|
||||
diff = np.abs(s1 - s2)
|
||||
matches = (diff <= 0.5).sum()
|
||||
|
||||
# Determine the denominator (total valid comparisons)
|
||||
valid_count = diff.notna().sum()
|
||||
|
||||
if valid_count > 0:
|
||||
percentage = (matches / valid_count) * 100
|
||||
else:
|
||||
percentage = 0
|
||||
|
||||
data_list.append({
|
||||
'GT': gt_col.replace('GT.', ''),
|
||||
'GT': base_name,
|
||||
'Match %': round(percentage, 1)
|
||||
})
|
||||
|
||||
|
||||
# 2. Prepare Data for Plotting
|
||||
match_df = pd.DataFrame(data_list)
|
||||
# We pivot to get a format suitable for a heatmap
|
||||
|
||||
@@ -69,3 +69,6 @@ styled_table
|
||||
|
||||
|
||||
|
||||
# Save the styled table to a file
|
||||
styled_table.to_html("agreement_report.html")
|
||||
print("Report saved to agreement_report.html")
|
||||
|
||||
Reference in New Issue
Block a user