提高机器学习模型中的公平性(预览版)Mitigate fairness in machine learning models (preview)

了解机器学习中的公平性以及 Fairlearn 开源 Python 包如何帮助你减少机器学习模型中的公平性问题。Learn about fairness in machine learning and how the Fairlearn open-source Python package can help you mitigate fairness issues in machine learning models. 如果不努力了解公平性问题以及如何在构建机器学习模型时评估公平性,那么你构建的模型可能会产生不公平的结果。If you are not making an effort to understand fairness issues and to assess fairness when building machine learning models, you may build models that produce unfair results.

Fairlearn 开源包用户指南的以下摘要介绍了如何使用它来评估正在构建的 AI 系统的公平性。The following summary of the user guide for the Fairlearn open-source package, describes how to use it to assess the fairness of the AI systems that you are building. Fairlearn 开源包还可以提供一些选项,以帮助缓解或减少你观察到的任何公平性问题。The Fairlearn open-source package can also offer options to help mitigate, or help to reduce, any fairness issues you observe. 请参阅操作方法示例笔记本,以便在有关 Azure 机器学习的训练期间启用 AI 系统的公平性评估。See the how-to and sample notebooks to enable fairness assessment of AI systems during training on Azure Machine Learning.

什么是机器学习模型中的公平性?What is fairness in machine learning models?

备注

公平性是一个社会性的技术难题。Fairness is a socio-technical challenge. 公平性的许多方面(例如公正和正当程序)没有通过量化的公平性指标进行捕获。Many aspects of fairness, such as justice and due process, are not captured in quantitative fairness metrics. 另外,许多量化的公平性指标无法同时得到满足。Also, many quantitative fairness metrics can't all be satisfied simultaneously. Fairlearn 开源包的目标是使人类能够评估不同的影响和缓解策略。The goal with the Fairlearn open-source package is to enable humans to assess different impact and mitigation strategies. 最终,由构建人工智能和机器学习模型的人类用户负责根据其应用场景进行权衡。Ultimately, it is up to the human users building artificial intelligence and machine learning models to make trade-offs that are appropriate to their scenario.

人工智能和机器学习系统可能会表现出不公平的行为。Artificial intelligence and machine learning systems can display unfair behavior. 定义不公平行为的一种方法是按其损害或对人的影响来定义。One way to define unfair behavior is by its harm, or impact on people. 人工智能系统可以造成许多类型的损害。There are many types of harm that AI systems can give rise to.

人工智能造成的两种常见损害是:Two common types of AI-caused harms are:

  • 对分配的损害:AI 系统会对特定群体提供或拒绝提供机会、资源或信息。Harm of allocation: An AI system extends or withholds opportunities, resources, or information for certain groups. 示例包括招聘、学校招生和贷款。在这些场景中,某个模型在特定人群中挑选优秀候选人的能力可能要强于在其他人群中进行挑选的能力。Examples include hiring, school admissions, and lending where a model might be much better at picking good candidates among a specific group of people than among other groups.

  • 对服务质量的损害:人工智能系统针对一个人群的工作质量没有针对另一个人群的工作质量好。Harm of quality-of-service: An AI system does not work as well for one group of people as it does for another. 例如,语音识别系统针对女性的工作质量可能没有针对男性的工作质量好。As an example, a voice recognition system might fail to work as well for women as it does for men.

为了减少人工智能系统中的不公平行为,你必须评估并缓解这些损害。To reduce unfair behavior in AI systems, you have to assess and mitigate these harms.

通过 Fairlearn 进行公平性评估和缓解Fairness assessment and mitigation with Fairlearn

Fairlearn 是一个开源 Python 包,它使机器学习系统开发者能够评估其系统的公平性并缓解所看到的公平性问题。Fairlearn is an open-source Python package that allows machine learning systems developers to assess their systems' fairness and mitigate the observed fairness issues.

Fairlearn 开源包有两个组件:The Fairlearn open-source package has two components:

  • 评估仪表板:这是一个 Jupyter 笔记本小组件,用于评估模型的预测如何影响不同的群体。Assessment Dashboard: A Jupyter notebook widget for assessing how a model's predictions affect different groups. 它还支持使用公平性和性能指标对多个模型进行比较。It also enables comparing multiple models by using fairness and performance metrics.
  • 缓解算法:一组用于在二元分类和回归中缓解不公平性的算法。Mitigation Algorithms: A set of algorithms to mitigate unfairness in binary classification and regression.

借助这些组件,数据科学家和业务主管能够在公平性和性能之间进行权衡,并选择最适合其需求的缓解策略。Together, these components enable data scientists and business leaders to navigate any trade-offs between fairness and performance, and to select the mitigation strategy that best fits their needs.

评估机器学习模型中的公平性Assess fairness in machine learning models

在 Fairlearn 开源包中,公平性通过一种称为“群体公平性”的方法进行概念化,该方法会询问以下问题:哪些群体有遭受损害的风险?In the Fairlearn open-source package, fairness is conceptualized though an approach known as group fairness, which asks: Which groups of individuals are at risk for experiencing harms? 相关群体(也称为亚群体)是通过敏感特征或敏感特性定义的。The relevant groups, also known as subpopulations, are defined through sensitive features or sensitive attributes. 敏感特征作为名为 sensitive_features 的矢量或矩阵传递给 Fairlearn 开源包中的估算器。Sensitive features are passed to an estimator in the Fairlearn open-source package as a vector or a matrix called sensitive_features. 此术语的意思是,系统设计者在评估群体公平性时应该对这些特征敏感。The term suggests that the system designer should be sensitive to these features when assessing group fairness.

需要注意的是,这些特征是否包含由于私有数据而产生的隐私影响。Something to be mindful of is whether these features contain privacy implications due to private data. 但是“敏感”并不意味着这些特征不应被用来进行预测。But the word "sensitive" doesn't imply that these features shouldn't be used to make predictions.

备注

公平性评估并非纯粹的技术练习。A fairness assessment is not a purely technical exercise. Fairlearn 开源包可帮助你评估模型的公平性,但不会为你执行评估。The Fairlearn open-source package can help you assess the fairness of a model, but it will not perform the assessment for you. Fairlearn 开源包会帮助识别量化指标以评估公平性,但开发人员还必须执行定性分析来评估其自己的模型的公平性。The Fairlearn open-source package helps identify quantitative metrics to assess fairness, but developers must also perform a qualitative analysis to evaluate the fairness of their own models. 上面所述的敏感特征是此类定性分析的一个示例。The sensitive features noted above is an example of this kind of qualitative analysis.

在评估阶段,将通过差异指标对公平性进行量化。During assessment phase, fairness is quantified through disparity metrics. 差异指标能够以比率或差值的形式评估并比较模型在不同群体中的行为。Disparity metrics can evaluate and compare model's behavior across different groups either as ratios or as differences. Fairlearn 开源包支持两类差异指标:The Fairlearn open-source package supports two classes of disparity metrics:

  • 模型性能差异:这些指标集计算所选性能指标的值在不同子群体之间的差异。Disparity in model performance: These sets of metrics calculate the disparity (difference) in the values of the selected performance metric across different subgroups. 示例包括:Some examples include:

    • 准确率差异disparity in accuracy rate
    • 错误率差异disparity in error rate
    • 精度差异disparity in precision
    • 召回率差异disparity in recall
    • MAE 差异disparity in MAE
    • 许多其他差异many others
  • 选择率差异:此指标包含不同子群体之间的选择率差异。Disparity in selection rate: This metric contains the difference in selection rate among different subgroups. 此差异的一个示例是贷款批准率差异。An example of this is disparity in loan approval rate. 选择率是指每个分类中归类为 1 的数据点所占的比例(在二元分类中)或者指预测值的分布(在回归中)。Selection rate means the fraction of datapoints in each class classified as 1 (in binary classification) or distribution of prediction values (in regression).

减少机器学习模型中的不公平性Mitigate unfairness in machine learning models

奇偶校验约束Parity constraints

Fairlearn 开源包包括了各种不公平性缓解算法。The Fairlearn open-source package includes a variety of unfairness mitigation algorithms. 这些算法支持对预测器行为的一组约束(称为奇偶校验约束或条件)。These algorithms support a set of constraints on the predictor's behavior called parity constraints or criteria. 奇偶校验约束要求预测器行为的某些方面在敏感特征所定义的群体(例如不同的种族)之间具有可比性。Parity constraints require some aspects of the predictor behavior to be comparable across the groups that sensitive features define (e.g., different races). Fairlearn 开源包中的缓解算法使用此类奇偶校验约束来缓解所观察到的公平性问题。The mitigation algorithms in the Fairlearn open-source package use such parity constraints to mitigate the observed fairness issues.

备注

缓解模型中的不公平性意味着降低不公平性,但这种技术上的缓解无法完全消除此不公平性。Mitigating unfairness in a model means reducing the unfairness, but this technical mitigation cannot eliminate this unfairness completely. Fairlearn 开源包中的不公平性缓解算法可提供建议的缓解策略,以帮助减少机器学习模型中的不公平性,但它们并不是用来完全消除不公平性的解决方案。The unfairness mitigation algorithms in the Fairlearn open-source package can provide suggested mitigation strategies to help reduce unfairness in a machine learning model, but they are not solutions to eliminate unfairness completely. 每个特定开发人员的机器学习模型可能还有其他应考虑的奇偶校验约束或条件。There may be other parity constraints or criteria that should be considered for each particular developer’s machine learning model. 使用 Azure 机器学习的开发人员必须自行确定,缓解措施是否充分消除其机器学习模型的预期使用和部署中的任何不公平性。Developers using Azure Machine Learning must determine for themselves if the mitigation sufficiently eliminates any unfairness in their intended use and deployment of machine learning models.

Fairlearn 开源包支持下列类型的奇偶校验约束:The Fairlearn open-source package supports the following types of parity constraints:

奇偶校验约束Parity constraint 目的Purpose 机器学习任务Machine learning task
人口统计奇偶校验Demographic parity 缓解分配损害Mitigate allocation harms 二元分类、回归Binary classification, Regression
均等几率Equalized odds 诊断分配和服务质量损害Diagnose allocation and quality-of-service harms 二元分类Binary classification
均等机会Equal opportunity 诊断分配和服务质量损害Diagnose allocation and quality-of-service harms 二元分类Binary classification
有界群体损失Bounded group loss 缓解服务质量损害Mitigate quality-of-service harms 回归Regression

缓解算法Mitigation algorithms

Fairlearn 开源包提供了后期处理和降低不公平性的缓解算法:The Fairlearn open-source package provides postprocessing and reduction unfairness mitigation algorithms:

  • 约简:这些算法采用标准的黑盒机器学习估算器(例如,LightGBM 模型),并使用一系列重新加权的训练数据集生成一组经过重新训练的模型。Reduction: These algorithms take a standard black-box machine learning estimator (e.g., a LightGBM model) and generate a set of retrained models using a sequence of re-weighted training datasets. 例如,某一性别的申请者可能会被提高或降低权重,然后重新训练模型,降低不同性别群体之间的差异。For example, applicants of a certain gender might be up-weighted or down-weighted to retrain models and reduce disparities across different gender groups. 然后,用户可以选择一个模型,该模型在准确性(或其他性能指标)与差异之间提供最佳的权衡,这一权衡通常需要基于业务规则和成本计算。Users can then pick a model that provides the best trade-off between accuracy (or other performance metric) and disparity, which generally would need to be based on business rules and cost calculations.
  • 后期处理:这些算法采用现有分类器和敏感特征作为输入。Post-processing: These algorithms take an existing classifier and the sensitive feature as input. 然后,它们将派生分类器的预测转换,以强制实施指定的公平性约束。Then, they derive a transformation of the classifier's prediction to enforce the specified fairness constraints. 阈值优化的最大优势在于其简易性和灵活性,因为它不需要重新训练模型。The biggest advantage of threshold optimization is its simplicity and flexibility as it does not need to retrain the model.
算法Algorithm 说明Description 机器学习任务Machine learning task 敏感特征Sensitive features 支持的奇偶校验约束Supported parity constraints 算法类型Algorithm Type
ExponentiatedGradient A Reductions Approach to Fair Classification(公平分类的约简方法)中描述的公平分类的黑盒方法Black-box approach to fair classification described in A Reductions Approach to Fair Classification 二元分类Binary classification 分类Categorical 人口统计奇偶校验均等几率Demographic parity, equalized odds 约简Reduction
GridSearch A Reductions Approach to Fair Classification(公平分类的约简方法)中描述的黑盒方法Black-box approach described in A Reductions Approach to Fair Classification 二元分类Binary classification 二进制Binary 人口统计奇偶校验均等几率Demographic parity, equalized odds 约简Reduction
GridSearch 一种黑盒方法,它通过公平回归:量化的定义和基于约简的算法中描述的用于有界群体损失的算法实现公平回归的网格搜索变体。Black-box approach that implements a grid-search variant of Fair Regression with the algorithm for bounded group loss described in Fair Regression: Quantitative Definitions and Reduction-based Algorithms 回归Regression 二进制Binary 有界群体损失Bounded group loss 约简Reduction
ThresholdOptimizer 基于 Equality of Opportunity in Supervised Learning(监督式学习中的机会均等性)一文的后期处理算法。Postprocessing algorithm based on the paper Equality of Opportunity in Supervised Learning. 此方法采用现有分类器和敏感特征作为输入,并派生分类器预测的单一转换,以强制实施指定的奇偶校验约束。This technique takes as input an existing classifier and the sensitive feature, and derives a monotone transformation of the classifier's prediction to enforce the specified parity constraints. 二元分类Binary classification 分类Categorical 人口统计奇偶校验均等几率Demographic parity, equalized odds 后处理Post-processing

后续步骤Next steps