敘述統計學
Descriptive Statistics
推論統計學
Inferential Statistics 多變量分析
Multivariate Analysis
資料由小至大排序,取四等份的分割點 第1四分位數 中位數 median(第2四分位數)第3四分位數 四分位距 IQR =
第3四分位數 − 第1四分位數
迴歸分析 #預測
Regression Analysis
相關係數
Correlation Coefficient (相關係數一般都是指「皮爾森積差相關係數」)
母體 Population ↘ 取樣 ↖ 推論 樣本 Sample \Large \fcolorbox {black}{#FBF3DB}{母體 Population} \normalsize \overset{取樣 }{\searrow} \\ \qquad \qquad \qquad \qquad \qquad \underset{ 推論}{\nwarrow} \fcolorbox {black}{#96F196} {樣本 Sample} 母體 Population ↘ 取樣 推論 ↖ 樣本 Sample
母體
樣本
不偏估計
x ‾ = μ ^ \overline x=\hat \mu x = μ ^
機率 Probability 大數法則 Law of Large Numbers 當實驗的次數趨於無限,實驗結果會趨於真值
全機率 Law of Total Probability In discrete case, if { B i : i = 1 , 2 , 3 , . . . } \ {\{B_i: i = 1,2,3,...\} } { B i : i = 1 , 2 , 3 , ... } is a finite or countably infinite set of mutually exclusive and collectively exhaustive events, then for any event A : \ A: A :
Pr ( A ) = ∑ i = 1 n Pr ( A ∩ B i ) = ∑ i = 1 n Pr ( A ∣ B i ) ∗ Pr ( B i ) \operatorname {Pr}(A) = \sum_{i=1}^{n} \operatorname {Pr}(A \cap B_i) = \sum_{i=1}^{n} \operatorname {Pr}(A \mid B_i) * \operatorname {Pr}(B_i) Pr ( A ) = ∑ i = 1 n Pr ( A ∩ B i ) = ∑ i = 1 n Pr ( A ∣ B i ) ∗ Pr ( B i )
隨機變數 Random Variables,機率分布 Probability Distribution 離散隨機變數
機率質量函數 Probability Mass Function Let X X X be a discrete random variable on a sample space S S S .
Then the probability mass function is
f ( x ) = Pr ( X = x ) f(x) = \operatorname {Pr}(X=x) f ( x ) = Pr ( X = x )
f ( x ) ≥ 0 for all x ∈ S f(x)≥0 \quad \text{for all } x∈S f ( x ) ≥ 0 for all x ∈ S
∑ x ∈ S f ( x ) = 1 \displaystyle \sum_{x \in S} f(x)=1 x ∈ S ∑ f ( x ) = 1
離散均勻分布 Discrete Uniform Distribution
伯努利分布 Bernoulli Distribution 二項式分布 Binomial Distribution
Poisson分布(卜瓦松、帕松)(對應指數分布) 幾何分布 Geometric Distribution 超幾何分布 hypergeometric Distribution
連續隨機變數
機率密度函數 Probability Density Function Let X X X be a continuous random variable.
A probability density function f ( x ) f(x) f ( x ) is an integrable
function where
∫ a b f ( x ) d x = Pr ( a < X ≤ b ) \int_a^b f(x)dx = \operatorname{Pr}(a<X≤b) ∫ a b f ( x ) d x = Pr ( a < X ≤ b )
f ( x ) ≥ 0 for all x ∈ R f(x)≥0 \quad \text{for all } x∈\Reals f ( x ) ≥ 0 for all x ∈ R
∫ − ∞ ∞ f ( x ) d x = 1 \int_{-\infin}^\infin f(x)dx = 1 ∫ − ∞ ∞ f ( x ) d x = 1
注意: f ( x ) f(x) f ( x ) 的值並不是機率
連續均勻分布 Continuous Uniform Distribution
高斯分布、常態分布 Normal Distribution
t分布 Stedent’s t-Distribution f分布 Fisher–Snedecor Distribution 對數常態分布 Log-normal Distribution 卡方分布 Chi-squared Distribution 指數分布 Exponential Distribution(對應 Poisson分布)
中央極限定理 Central Limit Theorem 從平均數μ \mu μ 、變異數σ 2 \sigma^2 \space σ 2 的母體中抽出大小為 n \space n \space n 的樣本;
若 n \space n \space n 的值愈大,
樣本平均數x ‾ \overline x \space x 的機率分配就會趨於「期望值μ \mu μ 、變異數σ 2 n \dfrac{\sigma^2}{n} \space n σ 2 的常態分配 」
信賴區間 Confidence Interval 用來說明你對一個估計的參數落在特定區間的信心程度
注意:95% 信賴區間,並不等於特定區間包含真實值的機率為 95%
檢定力 Power of a test Bruce B. Frey《你需要的統計指南在這裡!》,以 Cookbook 形式條列介紹每個檢定與統計方式(《There's a Stat for That!》)
如何設計研究 要處理的統計問題 適用的研究內容 數據範例 使用上的考量 實際的論文 ref. (作者的前一本書,《愛上統計學:使用SPSS》,書末很多英文資源、統計學歷史資源)
p-value 的六項指引 學術界長期濫用 p值、顯著性,生產了大量錯誤、無效的研究論文,因此 ASA 於 2016 年發佈了以下內容
p值可以指出資料與該模型的不相容程度 p值無法測量「虛無假設為真」的機率,也無法測量「資料是因隨機而生」的機率 科學結論與商業決策,都不應該只靠 p值來下判斷 正確的推論(Inference)需要完整的報告、完全透明 p值、顯著性,都不能測量效用的大小或是結果的重要性 p值本身,無法測量模型與假設的「證據」 (《不敗的數據學》Alex Reinhart,提供了許多統計實驗的操作細節,避免人們做出錯誤或虛假的結果)
聯合機率,邊際機率,條件機率
Pr ( A ) \operatorname{Pr}(A) Pr ( A )
白內障Pr ( ∼ A ) \operatorname{Pr}(\sim A) Pr ( ∼ A )
無白內障邊際機率
Marginal Probability
↓
Pr ( B ) \operatorname{Pr}(B) Pr ( B )
黃斑部病變0.2
0.05
0.25
Pr ( ∼ B ) \operatorname{Pr}(\sim B) Pr ( ∼ B )
無黃斑部病變0.6
0.15
0.75
邊際機率
Marginal Probability →
0.8
0.2
↓
→ 總合皆為1
藍色區塊為,聯合機率 Joint Probability Pr ( A ∩ B ) = 0.2 \operatorname{Pr}(A \cap B) \quad \quad = 0.2 Pr ( A ∩ B ) = 0.2 Pr ( A ∩ ∼ B ) = 0.6 \operatorname{Pr}(A \cap \sim B) \quad = 0.6 Pr ( A ∩ ∼ B ) = 0.6 Pr ( ∼ A ∩ B ) = 0.05 \operatorname{Pr}(\sim A \cap B) \quad = 0.05 Pr ( ∼ A ∩ B ) = 0.05 Pr ( ∼ A ∩ ∼ B ) = 0.15 \operatorname{Pr}(\sim A \cap \sim B) = 0.15 Pr ( ∼ A ∩ ∼ B ) = 0.15 淺紅區塊為,邊際機率 Marginal Probability Pr ( A ) = 0.8 \operatorname{Pr}(A) \quad = 0.8 \quad Pr ( A ) = 0.8 = Pr ( A ∩ B ) + Pr ( A ∩ ∼ B ) \quad = \operatorname{Pr}(A \cap B) + \operatorname{Pr}(A \cap \sim B) = Pr ( A ∩ B ) + Pr ( A ∩ ∼ B ) Pr ( B ) = 0.25 \operatorname{Pr}(B) \quad = 0.25 \quad Pr ( B ) = 0.25 = Pr ( A ∩ B ) + Pr ( ∼ A ∩ B ) \quad = \operatorname{Pr}(A \cap B) + \operatorname{Pr}(\sim A \cap B) = Pr ( A ∩ B ) + Pr ( ∼ A ∩ B ) Pr ( ∼ A ) = 0.2 \operatorname{Pr}(\sim A) = 0.2 \quad \; \; Pr ( ∼ A ) = 0.2 = Pr ( ∼ A ∩ B ) + Pr ( ∼ A ∩ ∼ B ) \quad = \operatorname{Pr}(\sim A \cap B) + \operatorname{Pr}(\sim A \cap \sim B) = Pr ( ∼ A ∩ B ) + Pr ( ∼ A ∩ ∼ B ) Pr ( ∼ B ) = 0.75 \operatorname{Pr}(\sim B) = 0.75 \quad Pr ( ∼ B ) = 0.75 = Pr ( A ∩ ∼ B ) + Pr ( ∼ A ∩ ∼ B ) \quad = \operatorname{Pr}(A \cap \sim B) + \operatorname{Pr}(\sim A \cap \sim B) = Pr ( A ∩ ∼ B ) + Pr ( ∼ A ∩ ∼ B )
條件機率 Conditional Probability 條件機率的表示方式
Pr ( A ∣ B ) \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} Pr ( A ∣ B )
Pr ( A ∣ ∼ B ) \operatorname{Pr}(A \mid \sim B) Pr ( A ∣∼ B )
Pr ( B ∣ A ) \colorbox{#D4A1FF}{$\operatorname{Pr}(B \mid A)$} Pr ( B ∣ A )
Pr ( B ∣ ∼ A ) \operatorname{Pr}(B \mid \sim A) Pr ( B ∣∼ A ) 條件機率的意思
Pr ( A ∣ B ) \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} Pr ( A ∣ B ) 是指「在 B \ B B 發生的前提下, A \ A A 發生的機率」
Pr ( A ∣ ∼ B ) \operatorname{Pr}(A \mid \sim B) Pr ( A ∣∼ B ) 是指「在 ∼ B \ \sim B ∼ B 發生的前提下, A \ A A 發生的機率」
以此類推。 條件機率的重要觀念 (可搭配上列表格以及自己畫個文氏圖來理解)Pr ( A ∣ B ) ≠ Pr ( B ∣ A ) \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} \color{red}{\bold \; \not = \;} \color{black} \colorbox{#D4A1FF}{$\operatorname{Pr}(B \mid A)$} Pr ( A ∣ B ) = Pr ( B ∣ A )
Pr ( A ∣ B ) = Pr ( A ∩ B ) Pr ( B ) ⋯ ⋯ 公式① \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$}=\dfrac{\colorbox {yellow}{$\operatorname{Pr}(A \cap B)$}} {\operatorname{Pr}(B)} \qquad \cdots \cdots \fcolorbox {black}{white}{公式①} Pr ( A ∣ B ) = Pr ( B ) Pr ( A ∩ B ) ⋯⋯ 公式 ①
Pr ( B ∣ A ) = Pr ( B ∩ A ) Pr ( A ) ⋯ ⋯ 公式② \colorbox{#D4A1FF}{$\operatorname{Pr}(B \mid A)$}=\dfrac{\colorbox {yellow}{$\operatorname{Pr}(B \cap A)$}} {\operatorname{Pr}(A)} \qquad \cdots \cdots \fcolorbox {black}{white}{公式②} Pr ( B ∣ A ) = Pr ( A ) Pr ( B ∩ A ) ⋯⋯ 公式 ②
如果 事件 A \ A A 與 事件 B \ B B 互相獨立,
那麼 Pr ( A ∣ B ) = Pr ( A ∣ ∼ B ) = Pr ( A ) \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} = \operatorname{Pr}(A \mid \sim B) = \operatorname{Pr}(A) Pr ( A ∣ B ) = Pr ( A ∣∼ B ) = Pr ( A )
所以 Pr ( A ) ∗ Pr ( B ) = Pr ( A ∩ B ) \operatorname{Pr}(A) * \operatorname{Pr}(B) = \colorbox {yellow}{$\operatorname{Pr}(A \cap B)$} Pr ( A ) ∗ Pr ( B ) = Pr ( A ∩ B )
貝氏定理 Bayes’ Theorem 根據條件機率的 公式① \fcolorbox {black}{white}{公式①} 公式 ① 與 公式② \fcolorbox {black}{white}{公式②} 公式 ② :
Pr ( A ∣ B ) ∗ Pr ( B ) = Pr ( B ∣ A ) ∗ Pr ( A ) \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} * \operatorname{Pr}(B) = \colorbox{#D4A1FF}{$\operatorname{Pr}(B \mid A)$} * \operatorname{Pr}(A) Pr ( A ∣ B ) ∗ Pr ( B ) = Pr ( B ∣ A ) ∗ Pr ( A )
於是可得出貝氏定理 :
Pr ( A ∣ B ) = Pr ( B ∣ A ) ∗ Pr ( A ) Pr ( B ) \colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} = \dfrac {\colorbox{#D4A1FF}{$\operatorname{Pr}(B \mid A)$} * \operatorname{Pr}(A)} {\operatorname{Pr}(B)} Pr ( A ∣ B ) = Pr ( B ) Pr ( B ∣ A ) ∗ Pr ( A )
貝氏推論 Bayesian Inference 貝氏推論是一種「科學方法」,透過新獲得的資料,來調整對於假設的主觀信心程度
《寫給大家的統計學》Will Kurt 貝氏統計,是一種用來描述自己相信的世界觀、對待「不確定性」的推理工具
Pr ( A ∣ B ) = Pr ( B ∣ A ) ∗ Pr ( A ) Pr ( B ) ⏡ 貝氏定理 = Pr ( B ∣ A ) ∗ Pr ( A ) Pr ( A ∩ B ) + Pr ( ∼ A ∩ B ) = Pr ( B ∣ A ) ∗ Pr ( A ) Pr ( B ∣ A ) ∗ Pr ( A ) + Pr ( B ∣ ∼ A ) ∗ Pr ( ∼ A ) ⏡ 用於貝氏推論 \underset {貝氏定理} {\undergroup {\colorbox{#00EE00}{$\operatorname{Pr}(A \mid B)$} = {\dfrac{\colorbox{#D4A1FF}{$\operatorname{Pr}(B \mid A)$} * \operatorname{Pr}(A)}{\operatorname{Pr}(B) }}}}=\dfrac{\operatorname{Pr}(B \mid A) * \operatorname{Pr}(A)}{\operatorname{Pr}(A \cap B)+\operatorname{Pr}(\sim A \cap B)}=\underset {用於貝氏推論} {\undergroup {\colorbox{#F7F4Fa}{$\dfrac{\operatorname{Pr}(B \mid A) * \operatorname{Pr}(A)}{\operatorname{Pr}(B \mid A) * \operatorname{Pr}(A)+\operatorname{Pr}(B \mid \sim A) * \operatorname{Pr}(\sim A)}$}}} 貝氏定理 Pr ( A ∣ B ) = Pr ( B ) Pr ( B ∣ A ) ∗ Pr ( A ) = Pr ( A ∩ B ) + Pr ( ∼ A ∩ B ) Pr ( B ∣ A ) ∗ Pr ( A ) = 用於貝氏推論 Pr ( B ∣ A ) ∗ Pr ( A ) + Pr ( B ∣∼ A ) ∗ Pr ( ∼ A ) Pr ( B ∣ A ) ∗ Pr ( A )
歸納法 Induction,演繹法 Deduction 經由假設、事實、實驗設計、資料等步驟,推導出意見或結論
[ 用語轉換 ] A → H (假設 H y p o t h e s i s 、 原因 ) B → D (資料 D a t a 、 結果 ) \color{gray}{[用語轉換]} \\ \space \\ \color{gray}{A \to H(假設Hypothesis、\fbox{原因})}\\ \space \\ \color{gray}{B \to D(資料Data、\qquad \quad \fbox{結果})} [ 用語轉換 ] A → H (假設 Hy p o t h es i s 、 原因 ) B → D (資料 D a t a 、 結果 )
Pr ( A ∣ B ) = Pr ( B ∣ A ) ∗ Pr ( A ) Pr ( B ∣ A ) ∗ Pr ( A ) + Pr ( B ∣ ∼ A ) ∗ Pr ( ∼ A ) ⏡ 用於貝氏推論 ⟶ 替換成貝氏推論的用語 Pr ( H ∣ D ) ↑ 後驗機率 = Pr ( D ∣ H ) ↘ 概似度 ∗ Pr ( H ) ↙ 先驗機率 Pr ( D ∣ H ) ∗ Pr ( H ) + Pr ( D ∣ ∼ H ) ∗ Pr ( ∼ H ) \colorbox{#00EE00} {$\operatorname{Pr}(A \mid B)$} = \underset {用於貝氏推論} {\undergroup {\colorbox{#F7F4Fa}{$\dfrac{\operatorname{Pr}(B \mid A) * \operatorname{Pr}(A)}{\operatorname{Pr}(B \mid A) * \operatorname{Pr}(A)+\operatorname{Pr}(B \mid \sim A) * \operatorname{Pr}(\sim A)}$}}} \qquad \overset{替換成貝氏推論的用語}{\longrightarrow} \qquad \underset{\large 後驗機率}{\underset {\large \uparrow}{\fcolorbox{red}{#00EE00} {$\operatorname{Pr}(H \mid D)$}}} = \dfrac { \overset{\large 概似度}{\overset{\large \searrow }{\fcolorbox{red}{white}{${\operatorname{Pr}(D \mid H)}$}}} * \overset{\large 先驗機率 }{\overset{\large \swarrow }{\fcolorbox{red}{white}{$\operatorname{Pr}(H)$}}}}{\operatorname{Pr}(D \mid H) * \operatorname{Pr}(H)+\operatorname{Pr}(D \mid \sim H) * \operatorname{Pr}(\sim H)} Pr ( A ∣ B ) = 用於貝氏推論 Pr ( B ∣ A ) ∗ Pr ( A ) + Pr ( B ∣∼ A ) ∗ Pr ( ∼ A ) Pr ( B ∣ A ) ∗ Pr ( A ) ⟶ 替換成貝氏推論的用語 後驗機率 ↑ Pr ( H ∣ D ) = Pr ( D ∣ H ) ∗ Pr ( H ) + Pr ( D ∣∼ H ) ∗ Pr ( ∼ H ) Pr ( D ∣ H ) ↘ 概似度 ∗ Pr ( H ) ↙ 先驗機率
概似度 Likehood 透過觀測到的資料而推測出來的「機率」;
概似度關心的是,已發生且已知結果的事件
先驗機率 Prior Probability 在獲得資料D之前,原因H成立的機率;
以主觀(subjective)來決定「覺得每項假設為真」的信心程度(degree of belief)
後驗機率 Posterior Probability 納入資料D計算後,原因H成立的機率
馬可夫鏈蒙地卡羅法 MCMC(Markov chain Monte Carlo) 蒙地卡羅 Monte Carlo 是一個從「已知的分佈」中,隨機採樣(generate)資料的方法 馬可夫鏈 Markov chain 是一個遍歷(traversal)模型
混淆矩陣 Confusion Matrix 實際狀況 實際狀況 陽性 陰性 預測 真陽性 TP 偽陽性 FP 陽性預測值 PPV 錯誤發現率 FDR 模擬 陽性 (True Positive) (False Positive) TP TP + FP 精確度 P r e c i s i o n FP TP + FP 快篩 型一錯誤 (Postive Predictive Value) (False Discovery Rate) 預測 偽陰性 FN 真陰性 TN 錯誤遺漏率 FOR 陰性預測值 NPV 模擬 陰性 (False Negative) (True Negative) FN FN + TN TN FN + TN 快篩 型二錯誤 (False Omission Rate) (Negative Predictive Value) 真陽性率 TPR 偽陽性率 FPR 靈敏度 S e n s i t i v i t y 召回率 R e c a l l TP TP + FN FP FP + TN 偽陰性率 FNR 真陰性率 TNR 特異度 S p e c i f i c i t y 正確率 A c c u r a c y FN TP + FN TN FP + TN TP + TN T P + T N + F P + F N f 1 − s c o r e 2 ∗ P r e c i s i o n ∗ R e c a l l P r e c i s i o n + R e c a l l (精確度和召回率的 調和平均數 ) F β = ( 1 + β 2 ) ∗ P r e c i s i o n ∗ R e c a l l β 2 ∗ P r e c i s i o n + R e c a l l \begin{array}{|c|c|c|c|c|c|}\hline & & {實際狀況} & {實際狀況} \\ \hline \\ & & \footnotesize \bold{陽性} & \footnotesize \bold{陰性} \\ \\ \hline {預測} & & {真陽性 \colorbox{#AAFFAA}{TP}} & {偽陽性 \colorbox{#FFAAAA}{FP}} & \text{陽性預測值 PPV} & \text{錯誤發現率 FDR} \\ {模擬} & \footnotesize \bold{陽性} & {\text{(True Positive)}} & \text{{(False Positive)}} & \dfrac{\colorbox{#AAFFAA}{TP}}{\colorbox{#AAFFAA} {TP}+\colorbox{#FFAAAA}{FP}} \fcolorbox{pink}{white}{$ \bold{精確度 \atop Precision}$} & \dfrac{\colorbox{#FFAAAA}{FP}}{\colorbox{#AAFFAA}{TP}+\colorbox{#FFAAAA}{FP}} \\ {快篩} & & & \fcolorbox{#AAAAFF}{yellow}{型一錯誤} & \footnotesize \text{{(Postive Predictive Value)}} & \footnotesize \text{{(False Discovery Rate)}} \\ \\ \hline {預測} & & {偽陰性 \colorbox{#CC7777}{FN}} & {真陰性 \colorbox{#55AA55}{TN}} & \text{錯誤遺漏率 FOR} & \text{陰性預測值 NPV} \\ {模擬} & \footnotesize \bold{陰性} & \text{(False Negative)} & \text{(True Negative)} & \dfrac{\colorbox{#CC7777}{FN}}{\colorbox{#CC7777}{FN}+\colorbox{#55AA55}{TN}} & \dfrac{\colorbox{#55AA55}{TN}}{\colorbox{#CC7777}{FN}+\colorbox{#55AA55}{TN}} \\ {快篩} & & \fcolorbox{#AAAAFF}{yellow}{型二錯誤} & & \footnotesize \text{(False Omission Rate)} & \footnotesize \text{(Negative Predictive Value)} \\ \\ \hline & & \text{真陽性率 TPR} & \text{偽陽性率 FPR} \\ & & \fcolorbox{pink}{white}{$ \bold{靈敏度 \atop Sensitivity}$} \space \fcolorbox{pink}{white}{$ \bold{召回率 \atop Recall}$} \\ & & \dfrac{\colorbox{#AAFFAA}{TP}}{\colorbox{#AAFFAA}{TP} + \colorbox{#CC7777}{FN}} & \dfrac{\colorbox{#FFAAAA}{FP}}{\colorbox{#FFAAAA}{FP} + \colorbox{#55AA55}{TN}} \\ \\ \hline & & \text{偽陰性率 FNR} & \text{真陰性率 TNR} \\ & & & \fcolorbox{pink}{white}{$ \bold{特異度 \atop Specificity}$} & & \fcolorbox{pink}{white}{$ \bold{正確率 \atop Accuracy}$} \\ & & \dfrac{\colorbox{#CC7777}{FN}}{\colorbox{#AAFFAA}{TP} + \colorbox{#CC7777}{FN}} & \dfrac{\colorbox{#55AA55}{TN}}{\colorbox{#FFAAAA}{FP} + \colorbox{#55AA55}{TN}} & & \dfrac{\colorbox{#AAFFAA}{TP}+\colorbox{#55AA55}{TN}}{TP+TN+FP+FN} \\ \\ \hline \\ & & & & \fcolorbox{pink}{white}{$ \bold{f1-score}$} \\ & & & & 2* \dfrac{Precision*Recall}{Precision+Recall} \\ & & & & \footnotesize (精確度和召回率的\fcolorbox{white}{#FBF3CA}{調和平均數}) \\ \\ & & & & \scriptsize \textcolor{#BBBBBB}{F_\beta = (1+\beta^2)*\dfrac{Precision*Recall}{\beta^2*Precision+Recall}} \\ \\ \hline \end{array} 預測 模擬 快篩 預測 模擬 快篩 陽性 陰性 實際狀況 陽性 真陽性 TP ( True Positive ) 偽陰性 FN ( False Negative ) 型二錯誤 真陽性率 TPR Sensitivity 靈敏度 Recall 召回率 TP + FN TP 偽陰性率 FNR TP + FN FN 實際狀況 陰性 偽陽性 FP ( False Positive ) 型一錯誤 真陰性 TN ( True Negative ) 偽陽性率 FPR FP + TN FP 真陰性率 TNR Specificity 特異度 FP + TN TN 陽性預測值 PPV TP + FP TP Precision 精確度 ( Postive Predictive Value ) 錯誤遺漏率 FOR FN + TN FN ( False Omission Rate ) f1 − score 2 ∗ P rec i s i o n + R ec a ll P rec i s i o n ∗ R ec a ll (精確度和召回率的 調和平均數 ) F β = ( 1 + β 2 ) ∗ β 2 ∗ P rec i s i o n + R ec a ll P rec i s i o n ∗ R ec a ll 錯誤發現率 FDR TP + FP FP ( False Discovery Rate ) 陰性預測值 NPV FN + TN TN ( Negative Predictive Value ) Accuracy 正確率 TP + TN + FP + FN TP + TN
機器學習 Machine Learning 資料處理 資料標準化 z-score Standardization:z = x − μ σ z=\dfrac{x-\mu}{\sigma} z = σ x − μ Min-max Normalization:x s c a l e d = x − x m i n x m a x − x m i n , x 介於 [ 0 , 1 ] x_{scaled} = \dfrac{x-x_{min}}{x_{max} - x_{min}},\space \footnotesize x \space 介於[0,1] x sc a l e d = x ma x − x min x − x min , x 介於 [ 0 , 1 ]
非線性轉換 L o g i s t i c Logistic \space L o g i s t i c 函數最簡單的形式:S i g m o i d Sigmoid \space S i g m o i d 函數可以將數值壓在 [ 0 , 1 ] , s ( x ) = 1 1 + e − a x , a 用來調整曲線陡度 [0,1], \space s(x) = \dfrac {1}{1+e^{-ax}} \space \footnotesize,a 用來調整曲線陡度 [ 0 , 1 ] , s ( x ) = 1 + e − a x 1 , a 用來調整曲線陡度 t a n h tanh \space t anh 函數可以將數值壓在 [ − 1 , 1 ] , t a n h ( x ) = e a x − e − a x e a x + e − a x , a 用來調整曲線陡度 [-1,1], \space tanh(x) = \dfrac {e^{ax} - e^{-ax}}{e^{ax} + e^{-ax}} \space \footnotesize,a 用來調整曲線陡度 [ − 1 , 1 ] , t anh ( x ) = e a x + e − a x e a x − e − a x , a 用來調整曲線陡度
資料降維 特徵選取 迴歸問題與分類問題各有作法,以下以 scikit-learn 為例
特徵萃取 主成分分析 PCA:常用於非監督式學習 線性區別分析 LDA:用於監督式學習
目標函數 Objective Function
成本函數 Cost Function
損失函數 Loss Function 上列函數名稱在實際使用上並無嚴格定義。
總之用來取得最大化(成果)或最小化(誤差)的函數 都會是這些名字。
迴歸 均方誤差 MSE(Mean Square Error) 平均絕對誤差 MAE(Mean Absolute Error) 均方對數誤差 MSLE(Mean Squared Logarithmic Error) 均方根誤差 RMSE(將MSE取根號) MAPE(將MAE取百分比) 均方根對數誤差 RMSLE(將MSLE曲跟好)
梯度下降 Gradient Descent 各種模型都能應用的最佳化演算法,反覆調整並取得最佳的參數,將損失函數最小化
監督式學習演算法 迴歸
Regression 對資料的極端值較敏感 〖分類〗Logistic regression 〖迴歸〗Linear regression 支持向量機
Support Vector Machine (SVM)
單純貝氏分類器
Naive Bayes Classifier 基於貝氏定理 Bayes’ Theorem 的 〖分類〗 模型 Gaussian Bernoulli Multinomial
隨機森林
Random Forest 非常複雜的決策樹 ensemble 預測能力佳,但結果難以解釋
k k k -最近鄰演算法
k k k -Nearest Neighbors(KNN)相對簡單的演算法,容易解釋,容易顯示出異常值 若資料集的分類規模不一致、或是維度較高,會使 KNN 效果較差
神經網路
Artificial Neural Network 非常複雜,需要較大的資料集與較多的運算資源 效果最佳,但難以解釋
常見的偏差 辛普森悖論 Simpson’s paradox 在分組數據裡呈現某種趨勢,但該趨勢在分組數據合為一組後,卻消失或反轉。
Cherry picking 採用有利於特定立場與結論的個案與特例,忽略不利於特地立場與結論的整體數據。
確認偏誤 Confirmation bias 傾向於收集符合自身信念與價值的資訊,來增強原先相信的想法;常見的行為有「模糊定義、重新解釋並修改記憶」。
p -hacking 濫用資料分析方法,以取得想要的統計顯著(Statistical Significance)結果。
即使演算法在分群、分類、分析、預測的表現很好,但仍然有一些潛在問題
Bradford Hill Criteria 流行病學用來判斷因果關係(Causality 、Causation 、Cause and effect )的準則,又稱 Hill’s criteria。
1. 強度 Strength 原因與結果之間的關聯(Association)有多強烈
2. 一致性 Consistency 不同研究者在不同地方使用不同的樣本觀察到了一樣的結果;再現性(Reproducibility)
3. 特異度 Specificity 特定地方的特定人群裡存在著無其他解釋的疾病,那麼其因果關係的機率會較高
4. 時間性 Temporality 原因必須發生在結果之前
5. 劑量反應關係 Dose-response relationship 較大的曝露量通常代表著更大的發生機率;生物梯度(Biological gradient)
6. 合理性 Plausibility 原因與結果之間有學理能說明其機制
(但學理機制可能受限於當下的科學知識)
7. 同調 Coherence 流行病學的調查結果與以往的實驗室研究結果相符
8. 實驗 Experiment 透過嚴謹的實驗證據證明
不確定性 Uncertainty(in Metrology) 參考資料 A Type A evaluation of standard uncertainty may be based on any valid statistical method for treating data.
Examples are calculating the standard deviation of the mean of a series of independent observations; using the method of least squares to fit a curve to data in order to estimate the parameters of the curve and their standard deviations; and carrying out an analysis of variance (ANOVA) in order to identify and quantify random effects in certain kinds of measurements. A Type B evaluation of standard uncertainty is usually based on scientific judgment using all of the relevant information available, which may include previous measurement data, experience with, or general knowledge of, the behavior and property of relevant materials and instruments manufacturer's specifications data provided in calibration and other reports uncertainties assigned to reference data taken from handbooks
自然常數 e=2.71828,以及自然對數 ln e e e 是無理數、超越數
e = 2.71828 18284 ⋯ = lim n → ∞ ( 1 + 1 n ) n = ∑ n = 0 ∞ 1 n ! = 1 + 1 1 + 1 1 ∗ 2 + 1 1 ∗ 2 ∗ 3 + … e = 2.71828 \space \color{gray}{18284} \color{black} \dots = \underset {n \to \infty } \lim \bigg ( 1 + \dfrac{1}{n} \bigg)^n = \sum_{n=0}^{\infin} \dfrac{1}{n!} = 1 + \dfrac{1}{1} + \dfrac{1}{1*2} + \dfrac{1}{1*2*3} + \dots e = 2.71828 18284 ⋯ = n → ∞ l i m ( 1 + n 1 ) n = ∑ n = 0 ∞ n ! 1 = 1 + 1 1 + 1 ∗ 2 1 + 1 ∗ 2 ∗ 3 1 + …
e = lim h → 0 ( 1 + h ) 1 h e = \underset {h \to 0} \lim \bigg(1 +h \bigg)^{\dfrac{1}{h}} e = h → 0 lim ( 1 + h ) h 1 ,經過等號兩邊各 h h h 次方的推導,lim h → 0 e h − 1 h = 1 \underset{h \to 0} \lim \colorbox{lightgray}{$\dfrac{e^h - 1}{h}$} = 1 h → 0 lim h e h − 1 = 1
f ( x ) = e x , f ˊ (x) = lim h → 0 f ( h + h ) − f ( x ) h = lim h → 0 e x e h − e x h = lim h → 0 e x ( e h − 1 h ) = e x \operatorname{f}(x) = e^x,\quad \colorbox{#FFAAAA}{f\' (x)} = \underset{h \to 0} \lim \dfrac{f(h+h) - f(x)}{h} = \underset{h \to 0} \lim \space \dfrac{e^xe^h - e^x}{h} = \underset{h \to 0} \lim \space e^x \colorbox{lightgray}{$(\dfrac{e^h - 1}{h})$} = \colorbox{#FFAAAA}{$e^x$} f ( x ) = e x , f ˊ (x) = h → 0 lim h f ( h + h ) − f ( x ) = h → 0 lim h e x e h − e x = h → 0 lim e x ( h e h − 1 ) = e x
log e x = ln x \log_e x = \operatorname{ln}x log e x = ln x
ln a = ∫ 1 a 1 x d x \operatorname{ln}a = \int_1^a \dfrac{1}{x} \space dx ln a = ∫ 1 a x 1 d x
書目 機器學習 《Bayesian Statistics for Beginners:A Step-by-Step Approach》 黃志勝《機器學習的統計基礎》 西內啟《機器學習的數學基礎:AI、深度學習打底必讀》 統計 涌井良幸、涌井貞美《誰都看得懂的統計學超圖解》 2015-08 二版,國立臺灣大學出版中心《統計與生活》 《臥底經濟學家的10堂數據偵探課》 搭配歷史實際案例,教你辨識每個統計陷阱,使用正確的情緒與態度解讀數據,以及正確地執行統計實驗 《寫給大家的統計學》 《簡單到不可思議的貝氏統計學》 《Machine Learning Design Patterns: Solutions to Common Challenges in Data Preparation, Model Building, and Mlops》