天天看点

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

黑匣子AI (Black-Box AI)

Explainability is extremely crucial in systems that are responsible for carrying out mission-critical tasks. For example, in healthcare, if scientists are relying on AI models to help them figure out whether the patient will have cancer or not, they need to be 100% sure of their diagnoses otherwise this can result in death, a lot of lawsuits and a lot of damage done in trust. Nature is this problem is so intense that explainability sits at the core of this problem: the data scientists and the human operators, in this case, the doctors need to understand how the machine learning system is behaving and how did it come to a decision.

在负责执行关键任务的系统中,可解释性至关重要。 例如,在医疗保健中,如果科学家依靠AI模型来帮助他们确定患者是否患有癌症,则需要100%确保自己的诊断,否则可能导致死亡,大量诉讼和诉讼。损害是由信任造成的。 本质就是这个问题如此激烈,以至于解释性成为这个问题的核心:在这种情况下,数据科学家和人类操作人员需要医生了解机器学习系统的行为方式以及如何做出决定。

Explainable AI is also important in finance or fintech in particular due to the growing adoption of machine learning solutions for credit scoring, loan approval, insurance, investment decisions and so on. Here again, there is a cost associated with the wrong decisions by the machine learning system: so there is a huge need to understand how the model actually works.

可解释的AI在金融或金融科技中也很重要,特别是由于越来越多地采用机器学习解决方案来进行信用评分,贷款审批,保险,投资决策等,因此AI也很重要。 同样,机器学习系统的错误决策也会带来成本:因此,非常需要了解模型的实际工作方式。

Using black-box AI increases business risk and exposes the businesses to a deep downside — from credit card applications to determining disease to criminal justice.

使用黑匣子AI会增加业务风险,并使业务面临深远的负面影响-从信用卡申请到确定疾病再到刑事司法。

The reason why black-box models are not desirable becomes more clear when we look at how the business functions as a whole:

当我们查看业务整体运作方式时,不希望使用黑匣子模型的原因变得更加清楚:

For the business decision-maker, data scientists need to answer the question of why they can trust our models, for IT & Operation, data scientists need to tell them how can they monitor and debug if an error occurs, for the data scientist, they need to know how they can further improve the accuracy of their models and finally, for regulators and auditors, they need to be able to get an answer to whether our AI system is fair or not?

对于业务决策者,数据科学家需要回答为什么他们可以信任我们的模型的问题;对于IT和运营,数据科学家需要告诉他们如何监控和调试是否发生错误;对于数据科学家,他们需要知道他们如何进一步提高模型的准确性,最后,对于监管机构和审计师,他们需要能够回答我们的AI系统是否公平?

输入可解释的AI (Enter explainable AI)

Explainable AI aims at providing clear and transparent predictions. An end-to-end system that provides decisions and explanations to the user and ultimately provides automated feedback to constantly improve the AI system. Remember, xAI is highly driven by the feedback so is a two-way interaction between the human and the AI system.

可解释的AI旨在提供清晰透明的预测。 端到端系统向用户提供决策和解释,并最终提供自动反馈以不断改进AI系统。 请记住,xAI在很大程度上受到反馈的驱动,因此人类与AI系统之间是双向交互。

In the end, we should understand why behind the model, the impact of the model, where the model fails and what recommendations to provide.

最后,我们应该了解模型背后的原因,模型的影响,模型失败之处以及提供哪些建议。

说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.)

explainx is an open-source explainable AI platform created by explainX.ai. Explainx, written in python, aims to help data scientists explain, monitor and debug black-box AI model — the purpose is to help build robust, unbiased and transparent AI applications.

describex是一个由explainX.ai创建的开源可解释 AI平台。 以Python编写的Explainx旨在帮助数据科学家解释,监视和调试黑匣子AI模型-目的是帮助构建健壮,无偏且透明的AI应用程序。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

explainx high-level architecture 说明高级架构

Within the explainx architecture, explainx provides access to state of the art interpretability techniques in just a single line of code within our Jupyter notebook.

在explaixx体系结构中,explainx可以在Jupyter笔记本中的单行代码中访问最新的可解释性技术。

For this example, we will use the HELOC dataset provided by FICO. The customers in this dataset have requested a credit line in the range of USD 5,000–150,000. Our job is to predict

RiskPerformance:

whether they will make timely payments over a two year period. The prediction can then be used to decide whether the homeowner qualifies for a line of credit.

在此示例中,我们将使用FICO提供的HELOC数据集。 此数据集中的客户要求的信用额度在5,000-150,000美元之间。 我们的工作是预测

RiskPerformance:

他们是否会在两年内及时付款。 然后,该预测可以用于确定房主是否符合信贷额度。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

Loan Application Approval — explainx.ai 贷款申请批准— describex.ai

For this example, we will train CatBoost classifier model. After the training is done, we will use the explainx xAI module to explain our model and build a narrative for a business user to understand!

对于此示例,我们将训练CatBoost分类器模型。 培训完成后,我们将使用explaixx xAI模块来解释我们的模型,并为业务用户构建一个叙述以供理解!

Let’s start with opening up our Jupyter notebooks and installing the explainx library. You can also clone the repository from the link below:

让我们从打开Jupyter笔记本并安装书信库开始。 您也可以从以下链接克隆存储库:

https://github.com/explainX/explainx

https://github.com/explainX/explainx

pip install explainx
           

Let’s import relevant packages:

让我们导入相关的软件包:

from explainx import *
import catboost
from sklearn.model_selection import train_test_split
           

Let’s load and pre-process our dataset for model building. The dataset is already available in the explainx library.

让我们加载和预处理我们的数据集以进行模型构建。 该数据集已经在explaixx库中可用。

X, y = explainx.dataset_heloc()#split data into train and test
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size=0.2, random_state=0
           

Begin training. For the sake of this tutorial, we are going to keep it simple!

开始训练。 为了本教程的缘故,我们将使其保持简单!

# Run catboost model
model = CatBoostClassifier(iterations=500,
                          learning_rate=.3,
                          depth=2)# Fit model
model.fit(X_train.to_numpy(), y_train)
           

After the training is done, we can simply pass the test data into the explainx function and get our explanations!

训练完成后,我们可以简单地将测试数据传递给explaixx函数并获得我们的解释!

explainx.ai(X_test, y_test, model, model_name="catboost")
           

Once explainx and running, all you need to do is point your browser to http://127.0.0.1:8050 and you’ll see a very nice user interface called explainX.Dashboard.

一旦运行了explaixx,您所需要做的就是将浏览器指向http://127.0.0.1:8050 ,您将看到一个非常漂亮的用户界面,称为explainX.Dashboard。

Note: If you want to view it inline, simple pass

mode="inline”

argument into the explainx function.

注意:如果要内联查看,请简单地将

mode="inline”

参数 传递 给explainx函数。

For this tutorial, we will not go in the nitty-gritty of model building, model metrics and evaluation. Instead, we will dive right into the explanation part which is the main aim of this tutorial. So let’s start opening up the black-box!

在本教程中,我们不会深入研究模型构建,模型指标和评估。 相反,我们将直接进入解释部分,这是本教程的主要目的。 因此,让我们开始打开黑匣子!

We will tackle the model at four levels:

我们将在四个层次上处理该模型:

Global Level Explanation

全局级别说明

Local Prediction Explanation

本地预测说明

Scenario Analysis

情景分析

Feature Interaction & Distributions

功能交互与分布

全局级别说明 (Global Level Explanation)

We will be using the overall feature importance and overall feature impact graphs to give us a basic underlying logic of the model.

我们将使用总体特征重要性和总体特征影响图为我们提供模型的基本底层逻辑。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

Global Feature Importance 全球特征重要性

Interpretation: This tells that according to the CatBoost model,

ExternalRiskEstimate, MSinceMostRecentInq and PercentTradesNeverDelq

are the top three variables with the largest impact on

RiskPerformance.

These three represents Risk Estimate, Credit Inquiries and Debt Level information: extremely important categories when assessing risk.

解释:这表明根据CatBoost模型,

ExternalRiskEstimate, MSinceMostRecentInq and PercentTradesNeverDelq

是对

RiskPerformance.

影响最大的前三个变量

RiskPerformance.

这三个代表风险估计,信用查询和债务水平信息:评估风险时极为重要的类别。

This information gives us a general idea of feature contribution but to understand whether each of these features has a positive or a negative impact on

RiskPerformance

we need to consult the feature impact graph.

这些信息为我们提供了特征贡献的总体思路,但是要了解这些特征中的每一个对

RiskPerformance

的正面还是负面影响,我们需要查阅特征影响图。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

Global Feature Impact 全球特征影响

This graph gives us even more insight into the model logic. We can clearly observe that

ExternalRiskEstimate

impacts the predicting variable positively — pushes it towards “Good Credit Risk Performance” and that matches our intuition as well. We have to use a little bit of our domain knowledge in finance for this:

ExternalRiskEstimate

is a consolidated version of some risk markers (higher is better) so automatically we learn that this variable will always positively affect the prediction. Then we have

NumSatisfactoryTrades:

the number of “satisfactory” accounts (“trades”) has a significant positive effect on the predicted probability of good credit.

该图使我们对模型逻辑有了更深入的了解。 我们可以清楚地看到,

ExternalRiskEstimate

对预测变量产生了积极的影响-将其推向“良好的信用风险表现”,并且也符合我们的直觉。 为此,我们必须使用我们在金融领域的一点点知识:

ExternalRiskEstimate

是某些风险标记的合并版本(越高越好),因此我们自动得知该变量将始终对预测产生积极影响。 然后我们得到

NumSatisfactoryTrades:

“满意”帐户(“交易”)的数量对良好信用的预测概率具有显着的积极影响。

However, in the lower end, delinquency variables push the overall prediction towards 0 (in this case, application denied). This is interesting and we can even dig deeper and see when does this negative effect of delinquency wears off? (Something to try on your own!)

但是,在较低端,违约变量将总体预测推向0(在这种情况下,应用程序被拒绝)。 这很有趣,我们甚至可以更深入地研究,看看这种犯罪的负面影响何时会消失? (可以自行尝试!)

Now as we have an idea of how each feature affects the prediction, we can move on to explaining a single prediction for a specific customer. For that, we will be using an impact graph or a decision plot that will help us get attribution scores for that particular prediction. To further support our analysis, we will calculate similar profiles that most closely resemble the one we are trying to predict.

现在,我们已经了解了每个功能部件如何影响预测,因此我们可以继续说明特定客户的单个预测。 为此,我们将使用影响图或决策图来帮助我们获得该特定预测的归因得分。 为了进一步支持我们的分析,我们将计算与我们试图预测的最相似的相似轮廓。

本地预测说明 (Local Prediction Explanation)

So let’s explain for customer on Row # 9 in our data. For this specific customer, the application was approved because the

RiskPerformance

was “Good” and our model also classified it correctly!

因此,让我们为数据中的第9行的客户进行解释。 对于该特定客户,该应用程序被批准,因为

RiskPerformance

为“良好”,并且我们的模型也对其进行了正确分类!

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

Customer Number 9 — Local Prediction Explanation 客户编号9-本地预测说明

Let’s explore the model logic:

让我们探索模型逻辑:

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

Local Feature Impact for Customer # 9 对客户9的本地功能的影响

So this graph clearly shows the top three positive and top three negatively impacting variables. According to the model,

MSinceMostRecentInq

had the most positive impact on the variable. So this tells us that the higher value of this variable means that there is no penalty for having more than one month since the most recent inquiry. Then we have

ExternalRiskEstimate

that again plays a positive role in pushing the prediction towards “good credit behaviour”. However,

PercentTradesNeverDelq

affected the prediction negatively: this might be the case if the value of this variable is extremely small because the smaller value for this variable lowers the probability of good credit score.

因此,此图清楚地显示了前三个正影响和前三个负影响变量。 根据模型,

MSinceMostRecentInq

对变量的影响最大。 因此,这告诉我们,此变量的值较高,意味着自最近一次查询以来,超过一个月没有任何罚款。 然后,我们有了

ExternalRiskEstimate

,它在将预测推向“良好的信用行为”方面也发挥了积极作用。 但是,

PercentTradesNeverDelq

对预测产生了负面影响:如果此变量的值非常小,则可能是这种情况,因为此变量的值越小,则信用分数越好。

To keep it short, these findings match our mental-models as the attribution score of each variable is correctly assigned. To further support our analysis, we will find similar customers!

为了简短起见,这些发现与我们的心理模型相符,因为正确分配了每个变量的归属分数。 为了进一步支持我们的分析,我们将找到类似的客户!

Explainx comes with an in-built prototypical analysis function which provides a much more well rounded and comprehensive view of why the decision for the applicant may be justifiable.

Explainx带有内置的原型分析功能,可以为申请人的决定为何合理的问题提供更加全面和全面的了解。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

The above table depicts the five closest user profiles to the chosen applicant. Based on importance weight assigned to each profile by the method, we see that the prototype under column zero is the most representative user profile by far. This is (intuitively) confirmed from the feature similarity where more than 50% of the features (12 out of 23) of this prototype are identical to that of the chosen user whose prediction we want to explain. Also, the bank employee looking at the prototypical users and their features surmise that the approved applicant belongs to a group with high values of ExternalRiskEstimate. This justification gives the bank employees more confidence in approving the user’s application.

上表描述了与所选申请人最接近的五个用户资料。 根据通过该方法分配给每个配置文件的重要性权重,我们看到到目前为止,列零下的原型是最具代表性的用户配置文件。 (从直觉上)从特征相似性得到了证实,该原型中超过50%的特征(23个中的12个)与我们要解释其预测的所选用户的特征相同。 同样,银行员工在查看原型用户及其特征时,也推测批准的申请人属于具有高ExternalRiskEstimate值的组。 这种理由使银行员工在批准用户的申请时更有信心。

情景分析 (Scenario Analysis)

Now, let’s explore different scenarios and see how the model performs. We can apply the data filters within the data table (no need to write SQL queries to filter your data) and explain multiple instances and scenarios very easily.

现在,让我们探索不同的场景并查看模型的性能。 我们可以在数据表中应用数据过滤器(无需编写SQL查询来过滤数据),并可以轻松地解释多个实例和场景。

This is extremely useful when you are trying to understand behaviour on a specific cluster or group of data. For example, we want to see if the model attributes the same weights to the users when the

ExternalRiskEstimate

is > 60 and

MSinceOldestTradeOpen

is greater than 200.

当您试图了解特定群集或一组数据上的行为时,这非常有用。 例如,我们想看看当

ExternalRiskEstimate

> 60且

MSinceOldestTradeOpen

大于200时,模型是否将相同的权重分配给用户。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

data filters applied — explainx 数据过滤器已应用—说明x

We can clearly see the dominance of ExternalRiskEstimate from the chart below.

从下面的图表中,我们可以清楚地看到ExternalRiskEstimate的优势。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

Feature Impact when RiskEstimate > 60 and TradeOpen > 200 当RiskEstimate> 60和TradeOpen> 200时功能影响

When the ExternalRiskEstimate is greater than 60, it is seen as a positive sign which matches our internal mental model as well: ExternalRiskEstimate is actually monotonically decreasing which means that as the value of ExternalRiskEstimate increases, the probability of Bad Credit Score decreases! So in this cluster where the RiskEstimate is greater than 60, we will have more Good customers who were extended the credit line. We can confirm this by using a feature interaction plot, specifically a partial dependence plot:

当ExternalRiskEstimate大于60时,它也被视为与我们内部心理模型相匹配的正号:ExternalRiskEstimate实际上单调下降,这意味着随着ExternalRiskEstimate值的增加,不良信用评分的可能性也会降低! 因此,在RiskEstimate大于60的集群中,我们将有更多扩展信用额度的良好客户。 我们可以使用特征相互作用图,特别是部分依赖图来确认这一点:

功能交互与分布 (Feature Interaction & Distribution)

The partial dependence plot validates our assumption. In the plot below, Red = Good RiskPerformance (credit line extended) and Silver = Bad RiskPerformance (credit line denied).

偏相关图验证了我们的假设。 在下面的图中,红色=良好的RiskPerformance(信用额度已延长),银=不良的风险性能(信用额度被拒绝)。

实际可解释的AI贷款批准用例 黑匣子AI (Black-Box AI) 输入可解释的AI (Enter explainable AI) 说明:一个开源,快速且可扩展的可解释AI平台。 (Explainx: An open-source, fast and scalable explainable AI platform.) 结论 (Conclusion)

We can clearly see that pattern that as ExternalRiskEstimate value increases, its impacts on the output also increases and we have more instances of good risk performance. We see more concentration of red dots as the ExternalRiskEstimate value goes up and that makes a lot of sense!

我们可以清楚地看到这种模式,随着ExternalRiskEstimate值的增加,其对产出的影响也随之增加,并且我们有更多具有良好风险表现的实例。 随着ExternalRiskEstimate值的增加,我们看到更多的红点集中,这很有意义!

结论 (Conclusion)

Data Scientists can use explainx to further explore patterns by looking at interactions between different variables and how they impact the overall prediction. So let’s end by summarizing our findings for a business user to understand:

数据科学家可以通过解释不同变量之间的相互作用以及它们如何影响总体预测,来使用解释器进一步探索模式。 因此,让我们最后总结一下我们的发现,以使业务用户可以理解:

  • According to the CatBoost model,

    ExternalRiskEstimate, MSinceMostRecentInq and PercentTradesNeverDelq

    are the top three variables with the largest impact on

    RiskPerformance.

    根据CatBoost模型,

    ExternalRiskEstimate, MSinceMostRecentInq and PercentTradesNeverDelq

    是对

    RiskPerformance.

    影响最大的前三个变量

    RiskPerformance.

  • ExternalRiskEstimate

    impacts the predicting variable positively — pushes it towards “Good Credit Risk” but delinquency variables push the overall prediction towards “Bad Credit Risk” (in this case, application denied).

    ExternalRiskEstimate

    对预测变量产生积极影响-将其推向“良好信用风险”,但拖欠变量将整体预测推向“不良信用风险”(在这种情况下,申请被拒绝)。
  • For our customer # 9, RiskPerformance = Good,

    ExternalRiskEstimate

    played a positive role in pushing the prediction towards “good credit behaviour”. However,

    PercentTradesNeverDelq

    affected the prediction negatively: this might be the case if the value of this variable is extremely small because the smaller value for this variable lowers the probability of good credit score.

    对于我们的9号客户,RiskPerformance = Good,

    ExternalRiskEstimate

    在将预测推向“良好信用行为”方面发挥了积极作用。 但是,

    PercentTradesNeverDelq

    对预测产生了负面影响:如果此变量的值非常小,则可能是这种情况,因为此变量的值越小,则信用分数越好。
  • We found customers that had very similar behaviour and variable values to our customer # 9: strengthening our hypothesis even more.

    我们发现客户的行为和变量值与我们的客户9非常相似:进一步加强了我们的假设。

  • We were able to validate the model’s logic by further exploring the PDP that clearly showed us how increasing the value of

    ExternalRiskEstimate

    increases the probability of loan approval.

    通过进一步研究PDP,我们能够验证模型的逻辑,该PDP清楚地向我们展示了增加

    ExternalRiskEstimate

    的值如何增加了贷款批准的可能性。
  • Data Scientist can further explore a similar process and build an even more comprehensive data narrative that anyone can easily understand.

    数据科学家可以进一步探索类似的过程,并构建更全面的数据叙述,任何人都可以轻松理解。

I hope you all enjoyed this case study. Explainability is extremely crucial and more than relevant today — so the ability to present a narrative that shows your understanding of how AI works is a vital skill for a data scientist. This is the real essence of human-AI understanding and democratization of AI.

我希望大家都喜欢这个案例研究。 可解释性是至关重要的,而且比今天要重要的多,因此提供陈述以表明您对AI的工作原理的理解能力对于数据科学家来说是一项至关重要的技能。 这是人类对AI的理解和AI民主化的真正实质。

Download explainx: https://github.com/explainX/explainxDocumentation: https://explainx-documentation.netlify.app/

下载说明x : https : //github.com/explainX/explainx文档: https : //explainx-documentation.netlify.app/

翻译自: https://towardsdatascience.com/practical-explainable-ai-loan-approval-use-case-f06d2fba4245