Spaces:
Sleeping
Sleeping
feat: add score threshold filtering options for original scores
Browse files
app.py
CHANGED
|
@@ -108,6 +108,22 @@ with st.sidebar:
|
|
| 108 |
page_size = st.selectbox("每張圖顯示幾個類別", [10, 20, 30, 50, 100], index=1)
|
| 109 |
sort_mode = st.selectbox("排序方式(原始成績)", ["依整體平均由高到低", "依整體平均由低到高", "依字母排序"])
|
| 110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
# === Baseline Δ 圖表的控制 ===
|
| 112 |
st.markdown("---")
|
| 113 |
st.subheader("差距分析設定(Baseline Δ)")
|
|
@@ -130,6 +146,14 @@ metric_plot = "accuracy_mean" + (" (x100)" if normalize_0_100 else "")
|
|
| 130 |
work[metric_plot] = work["accuracy_mean"] * (100.0 if normalize_0_100 else 1.0)
|
| 131 |
|
| 132 |
order_df = work.groupby("category")[metric_plot].mean().reset_index()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
if sort_mode == "依整體平均由高到低":
|
| 134 |
order_df = order_df.sort_values(metric_plot, ascending=False)
|
| 135 |
elif sort_mode == "依整體平均由低到高":
|
|
@@ -138,12 +162,21 @@ else:
|
|
| 138 |
order_df = order_df.sort_values("category", ascending=True)
|
| 139 |
|
| 140 |
cat_order = order_df["category"].tolist()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
work["category"] = pd.Categorical(work["category"], categories=cat_order, ordered=True)
|
| 142 |
|
| 143 |
n = len(cat_order)
|
| 144 |
pages = int(np.ceil(n / page_size))
|
| 145 |
|
| 146 |
st.markdown("## 📈 原始成績(各模型 × 類別)")
|
|
|
|
|
|
|
|
|
|
| 147 |
for p in range(pages):
|
| 148 |
start, end = p * page_size, min((p + 1) * page_size, n)
|
| 149 |
subset_cats = cat_order[start:end]
|
|
|
|
| 108 |
page_size = st.selectbox("每張圖顯示幾個類別", [10, 20, 30, 50, 100], index=1)
|
| 109 |
sort_mode = st.selectbox("排序方式(原始成績)", ["依整體平均由高到低", "依整體平均由低到高", "依字母排序"])
|
| 110 |
|
| 111 |
+
# === 分數閾值篩選 ===
|
| 112 |
+
st.markdown("---")
|
| 113 |
+
st.subheader("📏 分數篩選(原始成績)")
|
| 114 |
+
enable_threshold = st.checkbox("啟用分數閾值篩選", value=False)
|
| 115 |
+
if enable_threshold:
|
| 116 |
+
threshold_mode = st.radio("篩選模式", ["顯示 ≥ 閾值", "顯示 ≤ 閾值"])
|
| 117 |
+
# 根據顯示模式決定預設值與範圍
|
| 118 |
+
if normalize_0_100:
|
| 119 |
+
threshold_value = st.slider("閾值", min_value=0.0, max_value=100.0, value=50.0, step=1.0)
|
| 120 |
+
else:
|
| 121 |
+
threshold_value = st.slider("閾值", min_value=0.0, max_value=1.0, value=0.5, step=0.01)
|
| 122 |
+
st.caption(f"僅顯示平均分數{'≥' if threshold_mode == '顯示 ≥ 閾值' else '≤'} {threshold_value} 的類別")
|
| 123 |
+
else:
|
| 124 |
+
threshold_mode = None
|
| 125 |
+
threshold_value = None
|
| 126 |
+
|
| 127 |
# === Baseline Δ 圖表的控制 ===
|
| 128 |
st.markdown("---")
|
| 129 |
st.subheader("差距分析設定(Baseline Δ)")
|
|
|
|
| 146 |
work[metric_plot] = work["accuracy_mean"] * (100.0 if normalize_0_100 else 1.0)
|
| 147 |
|
| 148 |
order_df = work.groupby("category")[metric_plot].mean().reset_index()
|
| 149 |
+
|
| 150 |
+
# === 套用閾值篩選 ===
|
| 151 |
+
if enable_threshold and threshold_value is not None:
|
| 152 |
+
if threshold_mode == "顯示 ≥ 閾值":
|
| 153 |
+
order_df = order_df[order_df[metric_plot] >= threshold_value]
|
| 154 |
+
else: # "顯示 ≤ 閾值"
|
| 155 |
+
order_df = order_df[order_df[metric_plot] <= threshold_value]
|
| 156 |
+
|
| 157 |
if sort_mode == "依整體平均由高到低":
|
| 158 |
order_df = order_df.sort_values(metric_plot, ascending=False)
|
| 159 |
elif sort_mode == "依整體平均由低到高":
|
|
|
|
| 162 |
order_df = order_df.sort_values("category", ascending=True)
|
| 163 |
|
| 164 |
cat_order = order_df["category"].tolist()
|
| 165 |
+
|
| 166 |
+
# 如果篩選後沒有類別,顯示提示
|
| 167 |
+
if not cat_order:
|
| 168 |
+
st.warning(f"⚠️ 沒有類別符合篩選條件({threshold_mode}: {threshold_value}),請調整閾值或關閉篩選。")
|
| 169 |
+
st.stop()
|
| 170 |
+
|
| 171 |
work["category"] = pd.Categorical(work["category"], categories=cat_order, ordered=True)
|
| 172 |
|
| 173 |
n = len(cat_order)
|
| 174 |
pages = int(np.ceil(n / page_size))
|
| 175 |
|
| 176 |
st.markdown("## 📈 原始成績(各模型 × 類別)")
|
| 177 |
+
if enable_threshold and threshold_mode is not None:
|
| 178 |
+
st.info(f"🔍 已啟用篩選:顯示平均分數 {threshold_mode.replace('顯示 ', '')} {threshold_value} 的類別(共 {n} 個)")
|
| 179 |
+
|
| 180 |
for p in range(pages):
|
| 181 |
start, end = p * page_size, min((p + 1) * page_size, n)
|
| 182 |
subset_cats = cat_order[start:end]
|