Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- app_bayesian.py +21 -20
- bayesian_core.py +21 -16
- bayesian_llm_assistant.py +4 -3
- fire_water_converted.csv +47 -0
app_bayesian.py
CHANGED
|
@@ -110,7 +110,7 @@ if 'dag_img' not in st.session_state:
|
|
| 110 |
|
| 111 |
# 標題
|
| 112 |
st.title("🎲 Bayesian Hierarchical Model Analysis")
|
| 113 |
-
st.markdown("### 寶可夢
|
| 114 |
st.markdown("---")
|
| 115 |
|
| 116 |
# Sidebar
|
|
@@ -211,23 +211,24 @@ with st.sidebar:
|
|
| 211 |
with st.expander("📖 資料格式說明"):
|
| 212 |
st.markdown("""
|
| 213 |
**必要欄位格式:**
|
| 214 |
-
- `Trial_Type`:
|
| 215 |
-
- `
|
| 216 |
-
- `
|
| 217 |
-
- `
|
| 218 |
-
- `
|
| 219 |
|
| 220 |
**範例:**
|
| 221 |
```
|
| 222 |
-
Trial_Type,
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
```
|
| 227 |
-
""")
|
| 228 |
-
|
| 229 |
st.markdown("---")
|
| 230 |
|
|
|
|
| 231 |
# 關於系統
|
| 232 |
with st.expander("ℹ️ 關於此系統"):
|
| 233 |
st.markdown("""
|
|
@@ -241,12 +242,12 @@ with st.sidebar:
|
|
| 241 |
- 📊 階層模型(借用資訊)
|
| 242 |
- 📈 4 種視覺化圖表
|
| 243 |
- 💬 AI 助手解釋
|
| 244 |
-
- 🎮 對
|
| 245 |
-
|
| 246 |
**適用場景:**
|
| 247 |
-
- 分析
|
| 248 |
-
- 理解
|
| 249 |
-
-
|
| 250 |
""")
|
| 251 |
|
| 252 |
# 主要內容區 - 雙 Tab
|
|
@@ -259,17 +260,17 @@ with tab1:
|
|
| 259 |
# 載入資料
|
| 260 |
if data_source == "使用預設資料集":
|
| 261 |
# 檢查預設資料是否存在
|
| 262 |
-
default_data_path = "
|
| 263 |
if os.path.exists(default_data_path):
|
| 264 |
df = pd.read_csv(default_data_path)
|
| 265 |
-
st.success(f"✅ 已載入預設資料集({len(df)}
|
| 266 |
else:
|
| 267 |
st.warning("⚠️ 找不到預設資料集,請上傳您的資料")
|
| 268 |
df = None
|
| 269 |
else:
|
| 270 |
if uploaded_file is not None:
|
| 271 |
df = pd.read_csv(uploaded_file)
|
| 272 |
-
st.success(f"✅ 已載入資料({len(df)}
|
| 273 |
else:
|
| 274 |
df = None
|
| 275 |
st.info("📁 請在左側上傳 CSV 檔案")
|
|
|
|
| 110 |
|
| 111 |
# 標題
|
| 112 |
st.title("🎲 Bayesian Hierarchical Model Analysis")
|
| 113 |
+
st.markdown("### 火系 vs 水系寶可夢配對勝率的貝氏階層分析")
|
| 114 |
st.markdown("---")
|
| 115 |
|
| 116 |
# Sidebar
|
|
|
|
| 211 |
with st.expander("📖 資料格式說明"):
|
| 212 |
st.markdown("""
|
| 213 |
**必要欄位格式:**
|
| 214 |
+
- `Trial_Type`: 配對名稱(例如:Pair_1, Pair_2)
|
| 215 |
+
- `rt`: 火系(治療組)的勝場數
|
| 216 |
+
- `nt`: 火系的總場數
|
| 217 |
+
- `rc`: 水系(對照組)的勝場數
|
| 218 |
+
- `nc`: 水系的總場數
|
| 219 |
|
| 220 |
**範例:**
|
| 221 |
```
|
| 222 |
+
Trial_Type,rt,nt,rc,nc
|
| 223 |
+
Pair_1,122,133,22,145
|
| 224 |
+
Pair_2,85,132,17,135
|
| 225 |
+
Pair_3,52,129,41,134
|
| 226 |
```
|
| 227 |
+
""")
|
| 228 |
+
|
| 229 |
st.markdown("---")
|
| 230 |
|
| 231 |
+
|
| 232 |
# 關於系統
|
| 233 |
with st.expander("ℹ️ 關於此系統"):
|
| 234 |
st.markdown("""
|
|
|
|
| 242 |
- 📊 階層模型(借用資訊)
|
| 243 |
- 📈 4 種視覺化圖表
|
| 244 |
- 💬 AI 助手解釋
|
| 245 |
+
- 🎮 屬性對抗策略建議
|
| 246 |
+
|
| 247 |
**適用場景:**
|
| 248 |
+
- 分析火系對水系的配對勝率
|
| 249 |
+
- 理解不同配對間的異質性
|
| 250 |
+
- 評估屬性優劣勢
|
| 251 |
""")
|
| 252 |
|
| 253 |
# 主要內容區 - 雙 Tab
|
|
|
|
| 260 |
# 載入資料
|
| 261 |
if data_source == "使用預設資料集":
|
| 262 |
# 檢查預設資料是否存在
|
| 263 |
+
default_data_path = "fire_water_converted.csv"
|
| 264 |
if os.path.exists(default_data_path):
|
| 265 |
df = pd.read_csv(default_data_path)
|
| 266 |
+
st.success(f"✅ 已載入預設資料集({len(df)} 組配對)")
|
| 267 |
else:
|
| 268 |
st.warning("⚠️ 找不到預設資料集,請上傳您的資料")
|
| 269 |
df = None
|
| 270 |
else:
|
| 271 |
if uploaded_file is not None:
|
| 272 |
df = pd.read_csv(uploaded_file)
|
| 273 |
+
st.success(f"✅ 已載入資料({len(df)} 組配對)")
|
| 274 |
else:
|
| 275 |
df = None
|
| 276 |
st.info("📁 請在左側上傳 CSV 檔案")
|
bayesian_core.py
CHANGED
|
@@ -245,37 +245,42 @@ class BayesianHierarchicalAnalyzer:
|
|
| 245 |
|
| 246 |
def _interpret_results(self, or_mean, or_low, or_high, sigma_mean):
|
| 247 |
"""解釋分析結果"""
|
| 248 |
-
# 整體效應顯著性
|
| 249 |
if or_low > 1:
|
| 250 |
-
overall_effect = "
|
| 251 |
overall_significance = "顯著正效應"
|
| 252 |
elif or_high < 1:
|
| 253 |
-
overall_effect = "
|
| 254 |
overall_significance = "顯著負效應"
|
| 255 |
else:
|
| 256 |
-
overall_effect = "
|
| 257 |
-
overall_significance = "不顯著"
|
| 258 |
-
|
| 259 |
-
# 效果大小
|
| 260 |
if or_mean > 2:
|
| 261 |
-
effect_size = "大效果 (OR > 2)"
|
| 262 |
elif or_mean > 1.5:
|
| 263 |
-
effect_size = "中等效果 (OR > 1.5)"
|
| 264 |
elif or_mean > 1:
|
| 265 |
-
effect_size = "小效果 (OR > 1)"
|
| 266 |
elif or_mean == 1:
|
| 267 |
-
effect_size = "無差異 (OR = 1)"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
else:
|
| 269 |
-
effect_size = "
|
|
|
|
| 270 |
|
| 271 |
# 異質性評估
|
| 272 |
if sigma_mean > 0.5:
|
| 273 |
-
heterogeneity = "高異質性 - 不同
|
| 274 |
elif sigma_mean > 0.3:
|
| 275 |
-
heterogeneity = "中等異質性 - 不同
|
| 276 |
else:
|
| 277 |
-
heterogeneity = "低異質性 - 不同
|
| 278 |
-
|
| 279 |
return {
|
| 280 |
'overall_effect': overall_effect,
|
| 281 |
'overall_significance': overall_significance,
|
|
|
|
| 245 |
|
| 246 |
def _interpret_results(self, or_mean, or_low, or_high, sigma_mean):
|
| 247 |
"""解釋分析結果"""
|
| 248 |
+
# 整體效應顯著性
|
| 249 |
if or_low > 1:
|
| 250 |
+
overall_effect = "火系寶可夢相對於水系顯著更容易獲勝"
|
| 251 |
overall_significance = "顯著正效應"
|
| 252 |
elif or_high < 1:
|
| 253 |
+
overall_effect = "水系寶可夢相對於火系顯著更容易獲勝"
|
| 254 |
overall_significance = "顯著負效應"
|
| 255 |
else:
|
| 256 |
+
overall_effect = "火系與水系勝率無顯著差異"
|
| 257 |
+
overall_significance = "不顯著"
|
| 258 |
+
|
| 259 |
+
# 效果大小
|
| 260 |
if or_mean > 2:
|
| 261 |
+
effect_size = "大效果 (OR > 2) - 火系有明顯優勢"
|
| 262 |
elif or_mean > 1.5:
|
| 263 |
+
effect_size = "中等效果 (OR > 1.5) - 火系有一定優勢"
|
| 264 |
elif or_mean > 1:
|
| 265 |
+
effect_size = "小效果 (OR > 1) - 火系略有優勢"
|
| 266 |
elif or_mean == 1:
|
| 267 |
+
effect_size = "無差異 (OR = 1) - 火系與水系勢均力敵"
|
| 268 |
+
elif or_mean > 0.67:
|
| 269 |
+
effect_size = "小效果 (OR < 1) - 水系略有優勢"
|
| 270 |
+
elif or_mean > 0.5:
|
| 271 |
+
effect_size = "中等效果 (OR < 0.67) - 水系有一定優勢"
|
| 272 |
else:
|
| 273 |
+
effect_size = "大效果 (OR < 0.5) - 水系有明顯優勢"
|
| 274 |
+
|
| 275 |
|
| 276 |
# 異質性評估
|
| 277 |
if sigma_mean > 0.5:
|
| 278 |
+
heterogeneity = "高異質性 - 不同配對的勝率差異很大"
|
| 279 |
elif sigma_mean > 0.3:
|
| 280 |
+
heterogeneity = "中等異質性 - 不同配對的勝率有一定差異"
|
| 281 |
else:
|
| 282 |
+
heterogeneity = "低異質性 - 不同配對的勝率相對一致"
|
| 283 |
+
|
| 284 |
return {
|
| 285 |
'overall_effect': overall_effect,
|
| 286 |
'overall_significance': overall_significance,
|
bayesian_llm_assistant.py
CHANGED
|
@@ -47,8 +47,8 @@ class BayesianLLMAssistant:
|
|
| 47 |
|
| 48 |
你是一位精通貝氏階層模型和統合分析的統計專家,特別專注於寶可夢對戰統計分析。
|
| 49 |
|
| 50 |
-
Your role is to help users understand Bayesian hierarchical model results analyzing
|
| 51 |
-
你的角色是幫助使用者理解貝氏階層模型分析結果,了解
|
| 52 |
|
| 53 |
**NEW CAPABILITY: DAG Diagram Generation | 新能力:DAG 圖生成**
|
| 54 |
When users ask you to draw, create, or visualize a DAG (Directed Acyclic Graph) or model structure, you can generate Graphviz DOT code.
|
|
@@ -360,7 +360,8 @@ Format responses with proper markdown for better readability.
|
|
| 360 |
|
| 361 |
### Key Finding | 關鍵發現
|
| 362 |
{
|
| 363 |
-
f"On average,
|
|
|
|
| 364 |
if overall['or_mean'] > 1
|
| 365 |
else f"Interestingly, the data suggests no clear speed advantage or even a slight disadvantage. 有趣的是,資料顯示速度並無明顯優勢,甚至可能略有劣勢。"
|
| 366 |
}
|
|
|
|
| 47 |
|
| 48 |
你是一位精通貝氏階層模型和統合分析的統計專家,特別專注於寶可夢對戰統計分析。
|
| 49 |
|
| 50 |
+
Your role is to help users understand Bayesian hierarchical model results analyzing Fire vs Water Pokémon matchup win rates across different paired configurations.
|
| 51 |
+
你的角色是幫助使用者理解貝氏階層模型分析結果,了解火系對水系寶可夢在不同配對組合下的勝率差異。
|
| 52 |
|
| 53 |
**NEW CAPABILITY: DAG Diagram Generation | 新能力:DAG 圖生成**
|
| 54 |
When users ask you to draw, create, or visualize a DAG (Directed Acyclic Graph) or model structure, you can generate Graphviz DOT code.
|
|
|
|
| 360 |
|
| 361 |
### Key Finding | 關鍵發現
|
| 362 |
{
|
| 363 |
+
f"On average, Fire-type Pokémon are {overall['or_mean']:.2f} times more likely to win compared to Water-type (95% HDI: [{overall['or_hdi_low']:.2f}, {overall['or_hdi_high']:.2f}]). 平均而言,火系寶可夢獲勝的可能性是水系的 {overall['or_mean']:.2f} 倍 (95% HDI: [{overall['or_hdi_low']:.2f}, {overall['or_hdi_high']:.2f}])。"
|
| 364 |
+
|
| 365 |
if overall['or_mean'] > 1
|
| 366 |
else f"Interestingly, the data suggests no clear speed advantage or even a slight disadvantage. 有趣的是,資料顯示速度並無明顯優勢,甚至可能略有劣勢。"
|
| 367 |
}
|
fire_water_converted.csv
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Trial_Type,rt,nt,rc,nc
|
| 2 |
+
Pair_1,122,133,22,145
|
| 3 |
+
Pair_2,85,132,17,135
|
| 4 |
+
Pair_3,52,129,41,134
|
| 5 |
+
Pair_4,69,126,76,132
|
| 6 |
+
Pair_5,50,125,98,132
|
| 7 |
+
Pair_6,103,122,67,131
|
| 8 |
+
Pair_7,37,122,18,127
|
| 9 |
+
Pair_8,90,119,60,127
|
| 10 |
+
Pair_9,81,119,25,125
|
| 11 |
+
Pair_10,107,117,105,125
|
| 12 |
+
Pair_11,102,116,55,123
|
| 13 |
+
Pair_12,56,116,37,123
|
| 14 |
+
Pair_13,91,115,65,122
|
| 15 |
+
Pair_14,65,115,74,122
|
| 16 |
+
Pair_15,78,114,56,122
|
| 17 |
+
Pair_16,97,112,75,121
|
| 18 |
+
Pair_17,76,112,33,121
|
| 19 |
+
Pair_18,94,112,27,121
|
| 20 |
+
Pair_19,102,112,61,121
|
| 21 |
+
Pair_20,59,111,59,121
|
| 22 |
+
Pair_21,91,111,97,121
|
| 23 |
+
Pair_22,41,110,52,120
|
| 24 |
+
Pair_23,9,109,56,120
|
| 25 |
+
Pair_24,38,109,66,119
|
| 26 |
+
Pair_25,31,108,66,119
|
| 27 |
+
Pair_26,80,108,32,119
|
| 28 |
+
Pair_27,52,107,83,119
|
| 29 |
+
Pair_28,69,107,44,119
|
| 30 |
+
Pair_29,51,106,72,119
|
| 31 |
+
Pair_30,85,106,104,119
|
| 32 |
+
Pair_31,74,106,65,118
|
| 33 |
+
Pair_32,30,105,109,118
|
| 34 |
+
Pair_33,59,104,77,118
|
| 35 |
+
Pair_34,4,104,42,117
|
| 36 |
+
Pair_35,19,104,76,117
|
| 37 |
+
Pair_36,81,103,103,117
|
| 38 |
+
Pair_37,50,102,31,117
|
| 39 |
+
Pair_38,65,102,54,116
|
| 40 |
+
Pair_39,53,101,20,116
|
| 41 |
+
Pair_40,89,101,41,116
|
| 42 |
+
Pair_41,24,101,66,116
|
| 43 |
+
Pair_42,75,98,67,115
|
| 44 |
+
Pair_43,44,97,27,114
|
| 45 |
+
Pair_44,52,96,39,114
|
| 46 |
+
Pair_45,83,92,76,114
|
| 47 |
+
Pair_46,69,89,105,114
|