MLSTATKIT是一個綜合的Python庫,旨在將既定的統計方法無縫整合到機器學習項目中。它包含各種工具,包括DeLong的測試,用於比較兩個相關接收器操作特徵(ROC)曲線下的區域,用於計算置信區間的自動啟動, AUC2OR ,用於將接收器操作特徵曲線(AUC)下的區域轉換為幾個相關統計數據,例如Cohen的DESTICS,例如COHEN的DESTER _ PEARSON的RPB,INSTIRE for for pearson的rpb,and Natural for fords-grat and fords-grat and Natural and Natural and Natural and Natural and Idds and Idds and Idds and Idds and Iddio and Idds and Idds and Idd and rat rat rat rat,兩個模型指標之間差異的重要性是通過隨機調整數據並重新計算指標以創建差異分佈的意義。 MLSTATKIT憑藉其模塊化設計,為研究人員和數據科學家提供了一種靈活而強大的工具包,以增強其分析和模型評估,以滿足機器學習領域內的廣泛統計測試需求。
使用PIP直接從PYPI安裝MLSTATKIT:
pip install MLstatkitDelong_test函數可以對兩個相關接收器操作特徵(ROC)曲線下的區域之間的差異進行統計評估。這有助於對比較模型性能有更深入的了解。
true :形狀陣列(n_samples,)
範圍{0,1}的真實二進制標籤。
prog_a :形狀的陣列(n_samples,)
通過第一個模型預測概率。
prog_b :類似於陣列的形狀(n_samples,)
通過第二個模型預測概率。
Z_SCORE :浮動
比較兩個模型的AUC的z分數。
p_value :浮動
比較兩個模型的AUC的P值。
from MLstatkit . stats import Delong_test
# Example data
true = np . array ([ 0 , 1 , 0 , 1 ])
prob_A = np . array ([ 0.1 , 0.4 , 0.35 , 0.8 ])
prob_B = np . array ([ 0.2 , 0.3 , 0.4 , 0.7 ])
# Perform DeLong's test
z_score , p_value = Delong_test ( true , prob_A , prob_B )
print ( f"Z-Score: { z_score } , P-Value: { p_value } " )這證明了Delong_test的用法根據統計學的概率和真實標籤在統計上比較了兩個模型的AUC。返回的Z分數和P值有助於理解模型性能的差異是否具有統計學意義。
Bootstrapping功能使用引導函數計算指定性能指標的置信區間,從而衡量了估計的可靠性。它支持AUROC(ROC曲線下的區域),AUPRC(Precision-Recall曲線下的區域)和F1分數指標的計算。
from MLstatkit . stats import Bootstrapping
# Example data
y_true = np . array ([ 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 ])
y_prob = np . array ([ 0.1 , 0.4 , 0.35 , 0.8 , 0.2 , 0.3 , 0.4 , 0.7 , 0.05 ])
# Calculate confidence intervals for AUROC
original_score , confidence_lower , confidence_upper = Bootstrapping ( y_true , y_prob , 'roc_auc' )
print ( f"AUROC: { original_score :.3f } , Confidence interval: [ { confidence_lower :.3f } - { confidence_upper :.3f } ]" )
# Calculate confidence intervals for AUPRC
original_score , confidence_lower , confidence_upper = Bootstrapping ( y_true , y_prob , 'pr_auc' )
print ( f"AUPRC: { original_score :.3f } , Confidence interval: [ { confidence_lower :.3f } - { confidence_upper :.3f } ]" )
# Calculate confidence intervals for F1 score with a custom threshold
original_score , confidence_lower , confidence_upper = Bootstrapping ( y_true , y_prob , 'f1' , threshold = 0.5 )
print ( f"F1 Score: { original_score :.3f } , Confidence interval: [ { confidence_lower :.3f } - { confidence_upper :.3f } ]" )
# Calculate confidence intervals for AUROC, AUPRC, F1 score
for score in [ 'roc_auc' , 'pr_auc' , 'f1' ]:
original_score , conf_lower , conf_upper = Bootstrapping ( y_true , y_prob , score , threshold = 0.5 )
print ( f" { score . upper () } original score: { original_score :.3f } , confidence interval: [ { conf_lower :.3f } - { conf_upper :.3f } ]" )Permutation_test函數通過隨機調整數據並重新計算指標以創建差異分佈來評估兩個模型指標之間差異的統計學意義。此方法不假定數據的特定分佈,這是比較模型性能的強大選擇。
from MLstatkit . stats import Permutation_test
y_true = np . array ([ 0 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 ])
prob_model_A = np . array ([ 0.1 , 0.4 , 0.35 , 0.8 , 0.2 , 0.3 , 0.4 , 0.7 , 0.05 ])
prob_model_B = np . array ([ 0.2 , 0.3 , 0.25 , 0.85 , 0.15 , 0.35 , 0.45 , 0.65 , 0.01 ])
# Conduct a permutation test to compare F1 scores
metric_a , metric_b , p_value , benchmark , samples_mean , samples_std = Permutation_test (
y_true , prob_model_A , prob_model_B , 'f1'
)
print ( f"F1 Score Model A: { metric_a :.5f } , Model B: { metric_b :.5f } " )
print ( f"Observed Difference: { benchmark :.5f } , p-value: { p_value :.5f } " )
print ( f"Permuted Differences Mean: { samples_mean :.5f } , Std: { samples_std :.5f } " ) AUC2OR函數將曲線(AUC)值下方的區域轉換為優勢比(OR),並選擇返回中間值,例如T,Z,D和LN_OR。這種轉換對於理解AUC,二進制分類中的常見度量和OR之間的關係很有用,該度量通常用於統計分析。
from MLstatkit . stats import AUC2OR
AUC = 0.7 # Example AUC value
# Convert AUC to OR and retrieve all intermediate values
t , z , d , ln_OR , OR = AUC2OR ( AUC , return_all = True )
print ( f"t: { t :.5f } , z: { z :.5f } , d: { d :.5f } , ln_OR: { ln_OR :.5f } , OR: { OR :.5f } " )
# Convert AUC to OR without intermediate values
OR = AUC2OR ( AUC )
print ( f"OR: { OR :.5f } " )MLSTATTKIT中Delong_test的實現基於以下出版物:
用於計算置信區間的Bootstrapping方法不會直接引用單個出版物,而是一種被廣泛接受的統計技術,用於通過重新採樣替換來估計度量標準的分佈。有關引導方法的全面概述,請參見:
通過將兩個模型之間的性能指標差異差異和計算度量計算來評估兩個模型之間性能Permutation_tests差異的重要性。這種方法沒有做出特定的分佈假設,因此對於各種數據類型而言,它具有多功能性。有關置換測試的基礎討論,請參閱:
這些參考文獻為MLSTATKIT實施的統計測試和方法奠定了基礎,從而為用戶提供了對其科學基礎和適用性的深入了解。
AUR2OR函數將接收器操作特性曲線(AUC)下的區域轉換為幾個相關統計數據,包括Cohen的D,Pearson's RPB,ODDS-RATIO和自然日誌差異。這種轉換在解釋分類模型的性能方面特別有用。有關此轉換中使用的數學公式的詳細說明,請參閱:
這些參考文獻為AUR2OR函數提供了數學基礎,以確保用戶可以準確解釋其模型性能指標的統計意義和實際含義。
我們歡迎向Mlstatkit捐款!有關更多詳細信息,請參閱我們的貢獻指南。
MLSTATKIT根據MIT許可分配。有關更多信息,請參閱GITHUB存儲庫中的許可證文件。
0.1.7更新README.md0.1.6調試。0.1.5更新README.md ,添加AUC2OR函數。0.1.4更新README.md ,添加Permutation_tests函數,重新完成Bootstrapping參數。0.1.3更新README.md 。0.1.2添加Bootstrapping操作過程進度顯示。0.1.1更新README.md , setup.py 。添加CONTRIBUTING.md 。0.1.0第一版