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第一版