推荐开源项目:Uncertainty Quantification 360 (UQ360)——AI模型不确定性的全面解决方案
项目介绍
Uncertainty Quantification 360 (UQ360) 是一个开源的Python工具包,旨在为数据科学从业者和开发者提供最先进的算法,以简化和标准化机器学习模型不确定性的估计、评估、改进和沟通过程。作为AI透明度的常用实践,UQ360通过其交互式体验提供了一个温和的入门指南,并通过示例用例逐步展示其概念和能力。此外,教程和示例笔记本为数据科学家提供了更深入的介绍,而完整API也随时可用。
项目技术分析
UQ360基于Python开发,支持多种操作系统(macOS、Ubuntu和Windows)和Python 3.7版本。其核心功能包括:
- 不确定性估计算法:支持多种算法,如元模型、分位数回归等,用于增强模型的预测能力。
- 评估指标:提供如预测区间覆盖概率(PICP)等指标,帮助用户选择和优化模型。
- 扩展性:项目设计时考虑了扩展性,鼓励社区贡献新的不确定性估计算法、指标和应用。
UQ360依赖于多个开源库,如scikit-learn、Pytorch和Botorch,确保了其功能的强大和稳定性。
项目及技术应用场景
元模型应用
通过元模型增强sklearn的梯度提升回归器,添加预测区间。具体示例见这里。
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from uq360.algorithms.blackbox_metamodel import MetamodelRegression
# 创建训练、校准和测试集
X, y = make_regression(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
X_train, X_calibration, y_train, y_calibration = train_test_split(X_train, y_train, random_state=0)
# 训练基础模型
gbr_reg = GradientBoostingRegressor(random_state=0)
gbr_reg.fit(X_train, y_train)
# 训练元模型
uq_model = MetamodelRegression(base_model=gbr_reg)
uq_model.fit(X_calibration, y_calibration, base_is_prefitted=True)
# 获取测试数据的均值估计和预测区间
y_hat, y_hat_lb, y_hat_ub = uq_model.predict(X_test)
UQ360指标用于模型选择
使用预测区间覆盖概率(PICP)评分作为通过交叉验证选择模型的指标。具体示例见这里。
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
from sklearn.model_selection import GridSearchCV
from uq360.utils.misc import make_sklearn_compatible_scorer
from uq360.algorithms.quantile_regression import QuantileRegression
# 创建sklearn评分器
sklearn_picp = make_sklearn_compatible_scorer(
task_type="regression",
metric="picp", greater_is_better=True)
# 配置超参数
base_config = {"alpha":0.95, "n_estimators":20, "max_depth": 3,
"learning_rate": 0.01, "min_samples_leaf": 10,
"min_samples_split": 10}
configs = {"config": []}
for num_estimators in [1, 2, 5, 10, 20, 30, 40, 50]:
config = base_config.copy()
config["n_estimators"] = num_estimators
configs["config"].append(config)
# 创建训练测试集
X, y = make_regression(random_state=0)
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
# 初始化模型并使用GridSearchCV
uq_model = GridSearchCV(
QuantileRegression(config=base_config), configs, scoring=sklearn_picp)
# 训练模型
uq_model.fit(X_train, y_train)
# 获取测试集的预测区间
y_hat, y_hat_lb, y_hat_ub = uq_model.predict(X_test)
项目特点
- 全面性:涵盖不确定性估计、评估、改进和沟通的全流程。
- 易用性:提供交互式体验、教程和示例笔记本,帮助用户快速上手。
- 扩展性:设计灵活,鼓励社区贡献,持续丰富功能。
- 跨平台支持:支持多种操作系统和Python版本,适应不同用户需求。
总结
UQ360作为一个全面的不确定性量化工具包,为AI模型的透明度和可靠性提供了强有力的支持。无论是数据科学家还是开发者,都能从中受益,提升模型的预测能力和应用价值。立即访问UQ360官网,开启你的不确定性量化之旅吧!
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考