[{"data":1,"prerenderedAt":1039},["ShallowReactive",2],{"navigation_docs":3,"-data-analysis-pr-auc-for-imbalanced-classification":352,"-data-analysis-pr-auc-for-imbalanced-classification-surround":1034},[4,54,83,116,125,161,179,200],{"title":5,"path":6,"stem":7,"children":8},"Ai","/ai","ai",[9,12,42,46,50],{"title":10,"path":6,"stem":11},"AI 技術探索","ai/index",{"title":13,"path":14,"stem":15,"children":16,"page":41},"Rag","/ai/rag","ai/RAG",[17,21,25,29,33,37],{"title":18,"path":19,"stem":20},"BM25 演算法深入解析：從 TF-IDF 到現代搜尋引擎的核心技術","/ai/rag/bm25-deep-dive-from-tf-idf-to-rag","ai/RAG/bm25-deep-dive-from-tf-idf-to-rag",{"title":22,"path":23,"stem":24},"Dense Retrieval（向量檢索）深入解析","/ai/rag/dense-retrieval-deep-dive","ai/RAG/dense-retrieval-deep-dive",{"title":26,"path":27,"stem":28},"RAG（Retrieval-Augmented Generation）原理與實作入門","/ai/rag/rag-intro-principles-and-implementation","ai/RAG/rag-intro-principles-and-implementation",{"title":30,"path":31,"stem":32},"RAG Retrieval Strategy 深入解析","/ai/rag/rag-retrieval-strategy-deep-dive","ai/RAG/rag-retrieval-strategy-deep-dive",{"title":34,"path":35,"stem":36},"Reciprocal Rank Fusion（RRF）教學：打造更穩定的檢索融合策略","/ai/rag/rrf-reciprocal-rank-fusion-guide","ai/RAG/rrf-reciprocal-rank-fusion-guide",{"title":38,"path":39,"stem":40},"TF-IDF（Term Frequency–Inverse Document Frequency）深入解析","/ai/rag/tf-idf-deep-dive","ai/RAG/tf-idf-deep-dive",false,{"title":43,"path":44,"stem":45},"Docus AI 功能完整實作指南","/ai/docus-ai-implementation","ai/docus-ai-implementation",{"title":47,"path":48,"stem":49},"llms.txt 是什麼？在 Nuxt 中控制 AI 與搜尋引擎爬蟲的新方式","/ai/llms-txt","ai/llms-txt",{"title":51,"path":52,"stem":53},"MCP（Model Context Protocol）是什麼？用「AI 的 USB-C」理解模型如何安全連接工具與資料","/ai/mcp_concept","ai/mcp_concept",{"title":55,"path":56,"stem":57,"children":58,"page":41},"Data Analysis","/data-analysis","data-analysis",[59,63,67,71,75,79],{"title":60,"path":61,"stem":62},"Exploratory Data Analysis（EDA）資料探索分析入門","/data-analysis/exploratory-data-analysis-eda","data-analysis/exploratory-data-analysis-eda",{"title":64,"path":65,"stem":66},"PR-AUC 深入解析：不平衡分類問題的重要評估指標","/data-analysis/pr-auc-for-imbalanced-classification","data-analysis/pr-auc-for-imbalanced-classification",{"title":68,"path":69,"stem":70},"ROC-AUC 深入解析：理解分類模型的判斷能力","/data-analysis/roc-auc-complete-guide","data-analysis/roc-auc-complete-guide",{"title":72,"path":73,"stem":74},"SHAP（SHapley Additive exPlanations）模型解釋方法深入解析","/data-analysis/shap-model-interpretation-complete-guide","data-analysis/shap-model-interpretation-complete-guide",{"title":76,"path":77,"stem":78},"Social Network Analysis（SNA）深入解析","/data-analysis/social-network-analysis-sna","data-analysis/social-network-analysis-sna",{"title":80,"path":81,"stem":82},"Time-based Split：為什麼時間序列資料不能使用 Random Split？","/data-analysis/time-based-split-vs-random-split","data-analysis/time-based-split-vs-random-split",{"title":84,"path":85,"stem":86,"children":87,"page":41},"MachineLearning","/machine_learning","machine_learning",[88,92,96,100,104,108,112],{"title":89,"path":90,"stem":91},"Confusion Matrix（混淆矩陣）完整解析","/machine_learning/confusion-matrix","machine_learning/confusion-matrix",{"title":93,"path":94,"stem":95},"Decision Tree 模型完整教學：從原理到 Python 實作","/machine_learning/decision-tree-complete-guide","machine_learning/decision-tree-complete-guide",{"title":97,"path":98,"stem":99},"為什麼 Decision Tree 在 Tabular Data 上常常勝過 Deep Learning？","/machine_learning/decision-tree-vs-deep-learning-on-tabular-data","machine_learning/decision-tree-vs-deep-learning-on-tabular-data",{"title":101,"path":102,"stem":103},"LightGBM 模型入門：理解高效能的 Gradient Boosting 演算法","/machine_learning/lightgbm-intro-for-tabular-data","machine_learning/lightgbm-intro-for-tabular-data",{"title":105,"path":106,"stem":107},"Logistic Regression（Logit 回歸）完整教學","/machine_learning/logistic-regression-complete-guide","machine_learning/logistic-regression-complete-guide",{"title":109,"path":110,"stem":111},"為什麼模型訓練需要 Train / Validation / Test Dataset？","/machine_learning/train-validation-test-dataset","machine_learning/train-validation-test-dataset",{"title":113,"path":114,"stem":115},"XGBoost 原理與實務教學","/machine_learning/xgboost-complete-guide","machine_learning/xgboost-complete-guide",{"title":117,"path":118,"stem":119,"children":120,"page":41},"Network","/network","network",[121],{"title":122,"path":123,"stem":124},"DNS 設定入門：CNAME vs A Record 完整解析","/network/dns-cname-vs-a-record-guide","network/dns-cname-vs-a-record-guide",{"title":126,"path":127,"stem":128,"children":129},"Nuxt","/nuxt","nuxt",[130,133,137,141,145,149,153,157],{"title":131,"path":127,"stem":132},"Nuxt 實戰指南","nuxt/index",{"title":134,"path":135,"stem":136},"Abstraction Layer 與 Adapter 的差別，一次搞懂設計角色","/nuxt/adapter_abstraction_layer","nuxt/adapter_abstraction_layer",{"title":138,"path":139,"stem":140},"Nuxt 4 全面理解 — 專案檔案結構解析","/nuxt/directory_structure","nuxt/directory_structure",{"title":142,"path":143,"stem":144},"Nuxt 前端 build 流程完整解析","/nuxt/frontend_build","nuxt/frontend_build",{"title":146,"path":147,"stem":148},"Nitro 是什麼？從 Nuxt 專案到 Server 與 Edge 的關鍵引擎","/nuxt/nitro","nuxt/nitro",{"title":150,"path":151,"stem":152},"深入理解 Nuxt 的 .nuxt 與 .output：為什麼部署時一定要分清楚？","/nuxt/nuxt_and_output","nuxt/nuxt_and_output",{"title":154,"path":155,"stem":156},"Nuxt 中 dev、build、preview 的差異一次搞懂","/nuxt/nuxt_dev_build_preview","nuxt/nuxt_dev_build_preview",{"title":158,"path":159,"stem":160},"Nuxt Image vs \u003Cimg>：為什麼 Nuxt 3 專案幾乎都該用 \u003CNuxtImg>？","/nuxt/nuxt_image","nuxt/nuxt_image",{"title":162,"path":163,"stem":164,"children":165},"Python 程式開發","/python","python/index",[166,167,171,175],{"title":162,"path":163,"stem":164},{"title":168,"path":169,"stem":170},"如何在 FastAPI 中調用記憶體 Buffer 回傳圖片 (附實例)","/python/memory_buffer","python/memory_buffer",{"title":172,"path":173,"stem":174},"Python 單元測試教學：如何為你的程式撰寫 Test","/python/python-unit-testing-unittest-pytest","python/python-unit-testing-unittest-pytest",{"title":176,"path":177,"stem":178},"如何使用 uv 取代 pip：改善 Python 專案的開發流程","/python/uv","python/uv",{"title":180,"path":181,"stem":182,"children":183,"page":41},"Statistic","/statistic","statistic",[184,188,192,196],{"title":185,"path":186,"stem":187},"卡方檢定（Chi-Square Test）入門教學","/statistic/chi-square-test-intro","statistic/chi-square-test-intro",{"title":189,"path":190,"stem":191},"常見抽樣方法（Sampling Methods）教學：Stratified、Quota、Convenience、Systematic、Simple Random","/statistic/common-sampling-methods-guide","statistic/common-sampling-methods-guide",{"title":193,"path":194,"stem":195},"Cramér’s V 指標介紹：如何衡量兩個類別變數之間的關聯","/statistic/cramers-v-for-categorical-association","statistic/cramers-v-for-categorical-association",{"title":197,"path":198,"stem":199},"Mann–Whitney U 與 Kolmogorov–Smirnov（KS）檢定：非參數統計檢定的入門指南","/statistic/mann-whitney-u-and-ks-test-intro","statistic/mann-whitney-u-and-ks-test-intro",{"title":201,"path":202,"stem":203,"children":204},"WebDev","/web_dev","web_dev",[205,208,234,248,282,312,334],{"title":206,"path":202,"stem":207},"Web 前端開發","web_dev/index",{"title":209,"path":210,"stem":211,"children":212},"瀏覽器與渲染","/web_dev/browser","web_dev/browser/index",[213,214,218,222,226,230],{"title":209,"path":210,"stem":211},{"title":215,"path":216,"stem":217},"瀏覽器儲存空間完整解析：Cookie、localStorage、IndexedDB 到 Cache Storage","/web_dev/browser/browser-storage-comprehensive-guide","web_dev/browser/browser-storage-comprehensive-guide",{"title":219,"path":220,"stem":221},"DOM (Document Object Model) 深入解析","/web_dev/browser/dom","web_dev/browser/dom",{"title":223,"path":224,"stem":225},"Service Worker Request Flow 深入解析","/web_dev/browser/service-worker-request-flow","web_dev/browser/service-worker-request-flow",{"title":227,"path":228,"stem":229},"CSR、SSR 與 SSG 是什麼？前端渲染策略完整比較","/web_dev/browser/ssr_csr_ssg","web_dev/browser/ssr_csr_ssg",{"title":231,"path":232,"stem":233},"Virtual DOM 深入解析：為什麼它能優化前端效能？","/web_dev/browser/virtual_dom","web_dev/browser/virtual_dom",{"title":235,"path":236,"stem":237,"children":238},"圖形技術","/web_dev/graphics","web_dev/graphics/index",[239,240,244],{"title":235,"path":236,"stem":237},{"title":241,"path":242,"stem":243},"為什麼 Three.js 專案幾乎都選擇 CSR？從 SSR 問題談起","/web_dev/graphics/threejs_csr","web_dev/graphics/threejs_csr",{"title":245,"path":246,"stem":247},"WebGL 是什麼？為什麼前端 3D 幾乎都靠它？","/web_dev/graphics/webgl","web_dev/graphics/webGL",{"title":249,"path":250,"stem":251,"children":252},"架構與配置","/web_dev/infrastructure","web_dev/infrastructure/index",[253,254,258,262,266,270,274,278],{"title":249,"path":250,"stem":251},{"title":255,"path":256,"stem":257},"Zeabur + K3s + Nuxt 部署架構完整解析","/web_dev/infrastructure/k3s-zeabur","web_dev/infrastructure/K3s-zeabur",{"title":259,"path":260,"stem":261},"ECS vs Docker vs Kubernetes：從部署堆疊理解三層架構","/web_dev/infrastructure/ecs-docker-kubernetes-stack","web_dev/infrastructure/ecs-docker-kubernetes-stack",{"title":263,"path":264,"stem":265},"ECS vs VPS 是什麼？從部署網站的角度一次搞懂差別","/web_dev/infrastructure/ecs-vs-vps","web_dev/infrastructure/ecs-vs-vps",{"title":267,"path":268,"stem":269},"Zeabur 內網服務連線完整入門指南","/web_dev/infrastructure/k3s-internal-networking","web_dev/infrastructure/k3s-internal-networking",{"title":271,"path":272,"stem":273},"使用 Microservices 架構設計系統的優勢解析","/web_dev/infrastructure/microservices-architecture-advantages","web_dev/infrastructure/microservices-architecture-advantages",{"title":275,"path":276,"stem":277},"Nginx 入門教學：從反向代理到與 Kubernetes 的架構比較","/web_dev/infrastructure/nginx-intro","web_dev/infrastructure/nginx-intro",{"title":279,"path":280,"stem":281},"YAML 配置是什麼？為什麼現代開發都在用它","/web_dev/infrastructure/yaml-configuration","web_dev/infrastructure/yaml-configuration",{"title":283,"path":284,"stem":285,"children":286},"網絡與通訊","/web_dev/network","web_dev/network/index",[287,288,292,296,300,304,308],{"title":283,"path":284,"stem":285},{"title":289,"path":290,"stem":291},"HTTP Request 結構完整解析：從 Request Line 到 Header 一次看懂","/web_dev/network/http-request-structure","web_dev/network/http-request-structure",{"title":293,"path":294,"stem":295},"OSI 模型（Open Systems Interconnection Model）完整解析","/web_dev/network/osi-model","web_dev/network/osi-model",{"title":297,"path":298,"stem":299},"RESTful API 設計原則與實務解析","/web_dev/network/restful-api","web_dev/network/restful-api",{"title":301,"path":302,"stem":303},"RESTful API 五大設計原則深入解析","/web_dev/network/restful-api-principles","web_dev/network/restful-api-principles",{"title":305,"path":306,"stem":307},"Server-Sent Events (SSE) 深入解析與實作教學","/web_dev/network/sse-introduction","web_dev/network/sse-introduction",{"title":309,"path":310,"stem":311},"WebSocket 入門教學：從概念到 Node.js 實作","/web_dev/network/websocket-introduction","web_dev/network/websocket-introduction",{"title":313,"path":314,"stem":315,"children":316},"認證與安全","/web_dev/security","web_dev/security/index",[317,318,322,326,330],{"title":313,"path":314,"stem":315},{"title":319,"path":320,"stem":321},"使用 Cookie 與 Session 建立使用者驗證（完整新手教學）","/web_dev/security/cookie-session-authentication","web_dev/security/cookie-session-authentication",{"title":323,"path":324,"stem":325},"JWT 驗證機制完整解析：從登入流程到實務應用","/web_dev/security/jwt-authentication","web_dev/security/jwt-authentication",{"title":327,"path":328,"stem":329},"Secret Key 簽名是什麼？從零理解資料簽名的本質","/web_dev/security/secret-key-signing","web_dev/security/secret-key-signing",{"title":331,"path":332,"stem":333},"SSH（Secure Shell）是什麼？從遠端登入到安全通道的核心概念","/web_dev/security/ssh","web_dev/security/ssh",{"title":335,"path":336,"stem":337,"children":338},"SEO 與規範","/web_dev/seo","web_dev/seo/index",[339,340,344,348],{"title":335,"path":336,"stem":337},{"title":341,"path":342,"stem":343},"Canonical URL 是什麼？用生活化方式搞懂前端 SEO 的基本保命符","/web_dev/seo/canonical_link","web_dev/seo/canonical_link",{"title":345,"path":346,"stem":347},"robots.txt 是什麼？SEO 的第一道守門員","/web_dev/seo/robot_txt","web_dev/seo/robot_txt",{"title":349,"path":350,"stem":351},"Nuxt SEO 中的 Meta 與 SEO 工具是如何運作的？","/web_dev/seo/seo","web_dev/seo/seo",{"id":353,"title":64,"body":354,"description":1022,"extension":1023,"links":1024,"meta":1025,"navigation":770,"path":65,"seo":1032,"stem":66,"__hash__":1033},"docs/data-analysis/pr-auc-for-imbalanced-classification.md",{"type":355,"value":356,"toc":1008},"minimark",[357,362,371,374,389,392,396,407,411,417,420,423,426,442,445,448,451,454,460,463,466,468,476,479,482,485,487,491,498,505,516,519,522,575,578,592,601,603,607,610,618,621,624,627,630,642,645,647,651,658,672,678,685,688,696,699,701,705,713,900,903,912,919,921,925,928,948,951,963,966,968,971,977,980,982,985,1004],[358,359,361],"h2",{"id":360},"為什麼需要新的模型評估指標","為什麼需要新的模型評估指標？",[363,364,365,366,370],"p",{},"在機器學習的分類問題中，我們常常需要評估模型預測結果的好壞。最直覺的方式可能是看 ",[367,368,369],"strong",{},"Accuracy（準確率）","，也就是模型預測正確的比例。然而在許多真實世界的問題中，資料往往呈現**極度不平衡（imbalanced data）**的情況，此時 Accuracy 往往會失去參考價值。",[363,372,373],{},"例如在金融詐欺偵測中，假設 100 萬筆交易中只有 1000 筆是詐欺交易。如果一個模型直接把所有交易都預測為「正常交易」，那麼 Accuracy 仍然可以達到 99.9%。但這個模型其實完全沒有抓到任何詐欺交易，因此毫無實際價值。",[363,375,376,377,380,381,384,385,388],{},"因此，在這類問題中，我們更關注模型是否能 ",[367,378,379],{},"有效找到少數的重要事件","。這時候，Precision、Recall，以及由兩者組成的 ",[367,382,383],{},"Precision–Recall Curve"," 就成為非常重要的評估工具，而 ",[367,386,387],{},"PR-AUC"," 正是用來衡量這條曲線表現的重要指標。",[390,391],"hr",{},[358,393,395],{"id":394},"precision-與-recall-的核心概念","Precision 與 Recall 的核心概念",[363,397,398,399,402,403,406],{},"PR-AUC 的基礎建立在兩個非常重要的指標上：",[367,400,401],{},"Precision（精確率）"," 與 ",[367,404,405],{},"Recall（召回率）","。",[408,409,401],"h3",{"id":410},"precision精確率",[363,412,413,414,406],{},"Precision 描述的是：",[367,415,416],{},"模型預測為正類時，其中有多少是真的正類",[363,418,419],{},"其公式為：",[363,421,422],{},"$$\nPrecision = \\frac{TP}{TP + FP}\n$$",[363,424,425],{},"其中：",[427,428,429,436],"ul",{},[430,431,432,435],"li",{},[367,433,434],{},"TP（True Positive）","：預測為正類且實際為正類",[430,437,438,441],{},[367,439,440],{},"FP（False Positive）","：預測為正類但實際為負類",[363,443,444],{},"舉例來說，如果模型預測 100 筆交易為詐欺，其中只有 60 筆真的為詐欺，那麼：",[363,446,447],{},"$$\nPrecision = 0.6\n$$",[363,449,450],{},"這代表模型的預測中有 40% 是誤報。",[408,452,405],{"id":453},"recall召回率",[363,455,456,457,406],{},"Recall 描述的是：",[367,458,459],{},"所有真正的正類樣本中，有多少被模型成功找出來",[363,461,462],{},"公式為：",[363,464,465],{},"$$\nRecall = \\frac{TP}{TP + FN}\n$$",[363,467,425],{},[427,469,470],{},[430,471,472,475],{},[367,473,474],{},"FN（False Negative）","：實際為正類但模型預測為負類",[363,477,478],{},"如果資料中有 1000 筆詐欺交易，而模型只成功抓到 400 筆，那麼：",[363,480,481],{},"$$\nRecall = 0.4\n$$",[363,483,484],{},"這表示模型只找到了 40% 的詐欺交易。",[390,486],{},[358,488,490],{"id":489},"precisionrecall-curve-是什麼","Precision–Recall Curve 是什麼？",[363,492,493,494,497],{},"在多數分類模型中，模型輸出的其實不是直接的類別，而是 ",[367,495,496],{},"一個機率分數（probability score）","。例如模型可能預測某筆交易為詐欺的機率是 0.83。",[363,499,500,501,504],{},"為了將機率轉換成分類結果，我們需要設定一個 ",[367,502,503],{},"threshold（閾值）","。例如：",[427,506,507,510,513],{},[430,508,509],{},"threshold = 0.5",[430,511,512],{},"probability ≥ 0.5 → 預測為詐欺",[430,514,515],{},"probability \u003C 0.5 → 預測為正常",[363,517,518],{},"當我們改變 threshold 時，Precision 和 Recall 也會跟著改變。",[363,520,521],{},"例如：",[523,524,525,541],"table",{},[526,527,528],"thead",{},[529,530,531,535,538],"tr",{},[532,533,534],"th",{},"Threshold",[532,536,537],{},"Precision",[532,539,540],{},"Recall",[542,543,544,556,566],"tbody",{},[529,545,546,550,553],{},[547,548,549],"td",{},"0.9",[547,551,552],{},"高",[547,554,555],{},"低",[529,557,558,561,564],{},[547,559,560],{},"0.5",[547,562,563],{},"中",[547,565,563],{},[529,567,568,571,573],{},[547,569,570],{},"0.2",[547,572,555],{},[547,574,552],{},[363,576,577],{},"原因是：",[427,579,580,586],{},[430,581,582,585],{},[367,583,584],{},"提高 threshold"," → 模型更保守 → Precision 上升，但 Recall 下降",[430,587,588,591],{},[367,589,590],{},"降低 threshold"," → 模型更寬鬆 → Recall 上升，但 Precision 下降",[363,593,594,595,598,599,406],{},"如果我們將不同 threshold 下的 ",[367,596,597],{},"Recall 當作 X 軸，Precision 當作 Y 軸","，就可以畫出一條 ",[367,600,383],{},[390,602],{},[358,604,606],{"id":605},"pr-auc-是什麼","PR-AUC 是什麼？",[363,608,609],{},"PR-AUC（Precision-Recall Area Under Curve）指的是：",[611,612,613],"blockquote",{},[363,614,615],{},[367,616,617],{},"Precision–Recall Curve 下方的面積",[363,619,620],{},"這個面積用來衡量模型在不同 threshold 下的整體表現。",[363,622,623],{},"PR-AUC 的值介於：",[363,625,626],{},"$$\n0 \\le PR\\text{-}AUC \\le 1\n$$",[363,628,629],{},"一般來說：",[427,631,632,637],{},[430,633,634],{},[367,635,636],{},"PR-AUC 越接近 1 → 模型越好",[430,638,639],{},[367,640,641],{},"PR-AUC 越接近 0 → 模型越差",[363,643,644],{},"PR-AUC 可以理解為：模型在不同 recall 水準下，能維持多高 precision 的整體能力。",[390,646],{},[358,648,650],{"id":649},"為什麼-pr-auc-特別適合不平衡資料","為什麼 PR-AUC 特別適合不平衡資料？",[363,652,653,654,657],{},"PR-AUC 在 ",[367,655,656],{},"正負樣本極度不平衡","的情境中特別重要，例如：",[427,659,660,663,666,669],{},[430,661,662],{},"金融詐欺偵測",[430,664,665],{},"信用卡盜刷偵測",[430,667,668],{},"醫療疾病篩檢",[430,670,671],{},"垃圾郵件偵測",[363,673,674,675,406],{},"原因是 PR 曲線 ",[367,676,677],{},"只專注於正類（positive class）的預測品質",[363,679,680,681,684],{},"在 ROC 曲線中，評估指標包含 ",[367,682,683],{},"True Negative","，但在高度不平衡資料中，負樣本往往非常多，這會讓 ROC-AUC 看起來非常樂觀。",[363,686,687],{},"相反地，PR-AUC 更直接衡量：",[427,689,690,693],{},[430,691,692],{},"找到多少真正的正類（Recall）",[430,694,695],{},"找到的正類有多少是準確的（Precision）",[363,697,698],{},"因此在詐欺偵測這類問題中，PR-AUC 往往比 ROC-AUC 更具有參考價值。",[390,700],{},[358,702,704],{"id":703},"python-計算-pr-auc-的實例","Python 計算 PR-AUC 的實例",[363,706,707,708,712],{},"在 Python 中，我們可以透過 ",[709,710,711],"code",{},"sklearn"," 非常方便地計算 PR-AUC。",[714,715,720],"pre",{"className":716,"code":717,"language":718,"meta":719,"style":719},"language-python shiki shiki-themes github-dark","from sklearn.metrics import precision_recall_curve\nfrom sklearn.metrics import auc\nfrom sklearn.metrics import average_precision_score\n\ny_true = [0, 0, 0, 1, 1, 1]\ny_scores = [0.1, 0.4, 0.35, 0.8, 0.65, 0.9]\n\nprecision, recall, thresholds = precision_recall_curve(y_true, y_scores)\npr_auc = auc(recall, precision)\n\nprint(\"PR-AUC:\", pr_auc)\n","python","",[709,721,722,741,753,765,772,813,852,857,868,879,884],{"__ignoreMap":719},[723,724,727,731,735,738],"span",{"class":725,"line":726},"line",1,[723,728,730],{"class":729},"snl16","from",[723,732,734],{"class":733},"s95oV"," sklearn.metrics ",[723,736,737],{"class":729},"import",[723,739,740],{"class":733}," precision_recall_curve\n",[723,742,744,746,748,750],{"class":725,"line":743},2,[723,745,730],{"class":729},[723,747,734],{"class":733},[723,749,737],{"class":729},[723,751,752],{"class":733}," auc\n",[723,754,756,758,760,762],{"class":725,"line":755},3,[723,757,730],{"class":729},[723,759,734],{"class":733},[723,761,737],{"class":729},[723,763,764],{"class":733}," average_precision_score\n",[723,766,768],{"class":725,"line":767},4,[723,769,771],{"emptyLinePlaceholder":770},true,"\n",[723,773,775,778,781,784,788,791,793,795,797,799,802,804,806,808,810],{"class":725,"line":774},5,[723,776,777],{"class":733},"y_true ",[723,779,780],{"class":729},"=",[723,782,783],{"class":733}," [",[723,785,787],{"class":786},"sDLfK","0",[723,789,790],{"class":733},", ",[723,792,787],{"class":786},[723,794,790],{"class":733},[723,796,787],{"class":786},[723,798,790],{"class":733},[723,800,801],{"class":786},"1",[723,803,790],{"class":733},[723,805,801],{"class":786},[723,807,790],{"class":733},[723,809,801],{"class":786},[723,811,812],{"class":733},"]\n",[723,814,816,819,821,823,826,828,831,833,836,838,841,843,846,848,850],{"class":725,"line":815},6,[723,817,818],{"class":733},"y_scores ",[723,820,780],{"class":729},[723,822,783],{"class":733},[723,824,825],{"class":786},"0.1",[723,827,790],{"class":733},[723,829,830],{"class":786},"0.4",[723,832,790],{"class":733},[723,834,835],{"class":786},"0.35",[723,837,790],{"class":733},[723,839,840],{"class":786},"0.8",[723,842,790],{"class":733},[723,844,845],{"class":786},"0.65",[723,847,790],{"class":733},[723,849,549],{"class":786},[723,851,812],{"class":733},[723,853,855],{"class":725,"line":854},7,[723,856,771],{"emptyLinePlaceholder":770},[723,858,860,863,865],{"class":725,"line":859},8,[723,861,862],{"class":733},"precision, recall, thresholds ",[723,864,780],{"class":729},[723,866,867],{"class":733}," precision_recall_curve(y_true, y_scores)\n",[723,869,871,874,876],{"class":725,"line":870},9,[723,872,873],{"class":733},"pr_auc ",[723,875,780],{"class":729},[723,877,878],{"class":733}," auc(recall, precision)\n",[723,880,882],{"class":725,"line":881},10,[723,883,771],{"emptyLinePlaceholder":770},[723,885,887,890,893,897],{"class":725,"line":886},11,[723,888,889],{"class":786},"print",[723,891,892],{"class":733},"(",[723,894,896],{"class":895},"sU2Wk","\"PR-AUC:\"",[723,898,899],{"class":733},", pr_auc)\n",[363,901,902],{},"另一種更常見的方式是使用：",[714,904,906],{"className":716,"code":905,"language":718,"meta":719,"style":719},"average_precision_score(y_true, y_scores)\n",[709,907,908],{"__ignoreMap":719},[723,909,910],{"class":725,"line":726},[723,911,905],{"class":733},[363,913,914,915,918],{},"這個指標稱為 ",[367,916,917],{},"Average Precision (AP)","，在多數情況下與 PR-AUC 非常接近，因此在許多 Kaggle 競賽或研究中常被作為評估標準。",[390,920],{},[358,922,924],{"id":923},"pr-auc-在實務中的應用","PR-AUC 在實務中的應用",[363,926,927],{},"在實際應用中，PR-AUC 常常搭配其他指標一起使用，例如：",[427,929,930,936,942],{},[430,931,932,935],{},[367,933,934],{},"Precision@K","：在前 K 個預測結果中有多少是真的正類",[430,937,938,941],{},[367,939,940],{},"Recall@FPR","：在某個假陽性率下的召回率",[430,943,944,947],{},[367,945,946],{},"Confusion Matrix","：分析不同類型錯誤",[363,949,950],{},"在金融詐欺偵測系統中，一個常見的策略是：",[952,953,954,957,960],"ol",{},[430,955,956],{},"使用 PR-AUC 評估模型整體能力",[430,958,959],{},"再根據實際業務需求設定 threshold",[430,961,962],{},"控制誤報率（false positives）與漏報率（false negatives）",[363,964,965],{},"這樣才能在「抓到詐欺」與「避免誤報正常客戶」之間取得平衡。",[390,967],{},[358,969,970],{"id":970},"結論",[363,972,973,974,406],{},"PR-AUC 是 Precision–Recall Curve 下方的面積，用來衡量模型在不同 threshold 下的整體表現。與 Accuracy 或 ROC-AUC 相比，PR-AUC 更適合用於 ",[367,975,976],{},"正負樣本高度不平衡的分類問題",[363,978,979],{},"理解 Precision、Recall 與 PR Curve 的關係，可以幫助我們更深入理解模型在實際應用中的行為，並選擇更符合業務需求的評估方式。在金融詐欺偵測、醫療診斷或風險預測等領域中，PR-AUC 往往是比 Accuracy 更具價值的模型指標。",[390,981],{},[358,983,984],{"id":984},"參考資料",[952,986,987,995,998],{},[430,988,989,990,994],{},"Davis, J., & Goadrich, M. (2006). ",[991,992,993],"em",{},"The Relationship Between Precision-Recall and ROC Curves",".",[430,996,997],{},"scikit-learn documentation – Precision-Recall metrics.",[430,999,1000,1001,994],{},"Saito, T., & Rehmsmeier, M. (2015). ",[991,1002,1003],{},"The Precision-Recall Plot Is More Informative than the ROC Plot When Evaluating Binary Classifiers on Imbalanced Datasets",[1005,1006,1007],"style",{},"html pre.shiki code .snl16, html code.shiki .snl16{--shiki-default:#F97583}html pre.shiki code .s95oV, html code.shiki .s95oV{--shiki-default:#E1E4E8}html pre.shiki code .sDLfK, html code.shiki .sDLfK{--shiki-default:#79B8FF}html pre.shiki code .sU2Wk, html code.shiki .sU2Wk{--shiki-default:#9ECBFF}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}",{"title":719,"searchDepth":743,"depth":743,"links":1009},[1010,1011,1015,1016,1017,1018,1019,1020,1021],{"id":360,"depth":743,"text":361},{"id":394,"depth":743,"text":395,"children":1012},[1013,1014],{"id":410,"depth":755,"text":401},{"id":453,"depth":755,"text":405},{"id":489,"depth":743,"text":490},{"id":605,"depth":743,"text":606},{"id":649,"depth":743,"text":650},{"id":703,"depth":743,"text":704},{"id":923,"depth":743,"text":924},{"id":970,"depth":743,"text":970},{"id":984,"depth":743,"text":984},"了解 Precision-Recall Curve 與 PR-AUC 的概念、計算方式，以及為什麼在詐欺偵測與醫療診斷等不平衡資料問題中特別重要。","md",null,{"tags":1026,"category":57,"date":1031},[86,1027,1028,1029,1030],"evaluation","pr_auc","classification","data_science","2026-03-07",{"title":64,"description":1022},"SlQFPUZZkQ-5DIa--v2MlliQ1t5DG1K3UsC2pM4Nzh0",[1035,1037],{"title":60,"path":61,"stem":62,"description":1036,"children":-1},"介紹資料科學中 Exploratory Data Analysis（EDA）的核心概念、常見方法與實務流程，幫助理解資料特性並為後續建模做好準備。",{"title":68,"path":69,"stem":70,"description":1038,"children":-1},"介紹 ROC Curve 與 ROC-AUC 的概念、計算方式與實際應用，幫助理解分類模型在不同閾值下的表現。",1776690840770]