René's URL Explorer Experiment


Title: 引入业务先验约束的树模型(Python) · Issue #61 · aialgorithm/Blog · GitHub

Open Graph Title: 引入业务先验约束的树模型(Python) · Issue #61 · aialgorithm/Blog

X Title: 引入业务先验约束的树模型(Python) · Issue #61 · aialgorithm/Blog

Description: 一、模型解释性的意义 机器学习业务应用以输出决策判断为目标。可解释性是指人类能够理解决策原因的程度。机器学习模型的可解释性越高,人们就越容易理解为什么做出某些决定或预测。模型可解释性指对模型内部机制的理解以及对模型结果的理解。其重要性体现在:建模阶段,辅助开发人员理解模型,进行模型的对比选择,必要时优化调整模型;在投入运行阶段,向业务方解释模型的内部机制,对模型结果进行解释。比如基金推荐模型,需要解释:为何为这个用户推荐某支基金。 在机器学习应用中,有些领域(如金融风控...

Open Graph Description: 一、模型解释性的意义 机器学习业务应用以输出决策判断为目标。可解释性是指人类能够理解决策原因的程度。机器学习模型的可解释性越高,人们就越容易理解为什么做出某些决定或预测。模型可解释性指对模型内部机制的理解以及对模型结果的理解。其重要性体现在:建模阶段,辅助开发人员理解模型,进行模型的对比选择,必要时优化调整模型;在投入运行阶段,向业务方解释模型的内部机制,对模型结果进行解释。比如基金推荐模型...

X Description: 一、模型解释性的意义 机器学习业务应用以输出决策判断为目标。可解释性是指人类能够理解决策原因的程度。机器学习模型的可解释性越高,人们就越容易理解为什么做出某些决定或预测。模型可解释性指对模型内部机制的理解以及对模型结果的理解。其重要性体现在:建模阶段,辅助开发人员理解模型,进行模型的对比选择,必要时优化调整模型;在投入运行阶段,向业务方解释模型的内部机制,对模型结果进行解释。比如基金推荐模型...

Opengraph URL: https://github.com/aialgorithm/Blog/issues/61

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"引入业务先验约束的树模型(Python)","articleBody":"### 一、模型解释性的意义\r\n\u003e机器学习业务应用以输出决策判断为目标。可解释性是指人类能够理解决策原因的程度。机器学习模型的可解释性越高,人们就越容易理解为什么做出某些决定或预测。模型可解释性指对模型内部机制的理解以及对模型结果的理解。其重要性体现在:建模阶段,辅助开发人员理解模型,进行模型的对比选择,必要时优化调整模型;在投入运行阶段,向业务方解释模型的内部机制,对模型结果进行解释。比如基金推荐模型,需要解释:为何为这个用户推荐某支基金。\r\n\r\n在机器学习应用中,有些领域(如金融风控)的模型决策很看重业务的解释性,通过业务先验的知识加以调整并监控模型、以创造更值得信任的、安全可靠的模型。\r\n![](https://upload-images.jianshu.io/upload_images/11682271-a2eabe08bb528826.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n追求业务解释性,可以减少一些歧视、违规、不合理的特征决策,对模型带来类似正则化效果,可以减少统计噪音的影响(减少过拟合),有更好的泛化效果。\r\n\r\n\r\n但是,追求业务解释性是个繁琐的事情,首先你得有足够的业务应用知识的理解,其次还要手动不停地调整一版又一版的模型。业界上对合理的业务解释性可以提升模型的效果这是肯定的,特别是在小数据、数据不稳定的情况,\r\n\r\n一个金融领域简单的例子,如现有的1000条样本显示,有条数据规律:申请贷款的次数低于10,用户的贷款逾期概率就越大。但是结合业务来看,一个人频繁申请贷款,其负债、还款能力肯定是有问题的,这时仅凭这条现有数据规律去决策风险有点大,很大概率这条决策在更多样本的情况下就是失效的。\r\n\r\n我们通过解释性的工具剖析模型决策,当模型决策不符合合理的业务逻辑或法规什么的 ,这时,就很有必要做一些特征选择,调整模型,以符合业务解释性:\r\n\r\n- 如经典的逻辑回归-lr ,需要不断凭借业务含义调整特征分箱决策的单调性:\r\n[一文梳理金融风控建模全流程(Python)](https://mp.weixin.qq.com/s?__biz=MzI4MDE1NjExMQ==\u0026mid=2247489574\u0026idx=1\u0026sn=98ca40dd2775428963b50a05e3a1f06c\u0026chksm=ebbd9a86dcca1390c85fe18b330db1f8c0458a783a8d327c65a74fbcb38f2b72390dc64c4fe2\u0026scene=178\u0026cur_album_id=1986073923821551618#rd)\r\n\r\n- 如树模型,[一个简单的剪枝调整业务解释性的方法](https://mp.weixin.qq.com/s/K5RwETMk4S7XmHKkTFxrmg)。\r\n\r\n\r\n\r\n### 二、引入业务先验约束的树模型(GBDT)\r\n\r\n但上面两种方法都比较依赖于手动微调模型,以符合业务解释性。为什么不直接在训练过程中,直接依据业务先验知识辅助模型训练?\r\n\r\n在此,本文另提出一个思路,通过在树模型学习训练过程(树节点的分裂过程),简单引入个业务先验约束,以符合决策过程符合业务解释性。\r\n![](https://upload-images.jianshu.io/upload_images/11682271-da4a430f7eb4cbf6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n\r\n大致步骤是,\r\n\r\n#### 在 GBDT训练代码中,配置特征业务逻辑性的约束 \r\n\r\n如 当前二分类数据集有age,weight两个特征。假设我们从业务理解上,认为年龄age应该和标签是呈现负相关的,年龄数值越大,标签值应该要越小。那我们就可以配置特征约束的字典feas_logit, 配置特征age业务逻辑性的约束, 新增{'age': -1}, 其中-1代表该特征与标签的业务规律约束为负相关,+1代表正相关。暂不支持非单调关系的业务约束配置。\r\n```   \r\n # 配置特征业务逻辑性的约束\r\n    feas_logit = {'age': -1}\r\n```\r\n    \r\n#### 特征节点分裂时加入业务逻辑判断(约束)\r\n\r\nGBDT是cart二叉决策树集成实现的,对于每一棵cart树,我们会遍历所有特征,尝试以每一特征值作为决策的分裂点。我们可以在这里加入约束限制,如年龄age特征,我们认为它和标签值是负相关的,那么对于每次分类age\u003c特征阈值的左边分支的样本群体的标签均值应该大于右边分支的(反之亦然)。如果树生长的特征分裂不符合业务逻辑的,则会略过,继续其他特征值的搜索。\r\n```\r\n# 完整代码:[aialgorithm](https://github.com/aialgorithm/Blog)\r\nfor feature in self.features:\r\n\tself.logger.info(('----划分特征:', feature))\r\n\tfeature_values = now_data[feature].unique()\r\n\tfor fea_val in feature_values:\r\n\t\t# 尝试划分\r\n\t\tleft_index = list(now_data[feature] \u003c fea_val)\r\n\t\tright_index = list(now_data[feature] \u003e= fea_val)\r\n\t\tleft_labelvalue = now_data[left_index][self.target_name]\r\n\t\tright_labelvalue = now_data[right_index][self.target_name]\r\n\t\t# 该特征划分  加入判断业务逻辑合理性约束##\r\n\t\tif feature in self.feas_logit:  # 如果该划分不符合业务合理性约束则继续搜索其他划分\r\n\t\t\tif not self.feas_logit[feature]*right_labelvalue.mean() \u003e self.feas_logit[feature]*left_labelvalue.mean(): \r\n\t\t\t\tcontinue\r\n\r\n\t\t# 计算划分后的损失\r\n\t\tleft_se = calculate_se(left_labelvalue)\r\n\t\tright_se = calculate_se(right_labelvalue)\r\n\t\tsum_se = left_se + right_se\r\n\t\tself.logger.info(('------划分值:%.3f,左节点损失:%.3f,右节点损失:%.3f,总损失:%.3f' %\r\n\t\t\t\t\t\t  (fea_val, left_se, right_se, sum_se)))\r\n\t\tif se is None or sum_se \u003c se:\r\n\t\t\tsplit_feature = feature\r\n\t\t\tsplit_value = fea_val\r\n\t\t\tse = sum_se\r\n\t\t\tleft_index_of_now_data = left_index\r\n\t\t\tright_index_of_now_data = right_index\r\n```\r\n\r\n\r\n\r\n\r\n\r\n#### 代码运行\r\n\r\n- 依赖环境:\r\n- 操作系统:Windows/Linux\r\n- 编程语言:Python3\r\n- Python库:pandas、PIL、pydotplus,\r\n 其中pydotplus库会自动调用Graphviz,所以需要去[Graphviz官网](https://graphviz.gitlab.io/_pages/Download/Download_windows.html)下载`graphviz的-2.38.msi`\r\n,先安装,再将安装目录下的`bin`添加到系统环境变量,此时如果再报错可以重启计算机。详细过程不再描述,网上很多解答。\r\n\r\n文件结构(修改前GBDT手写代码如参考文末链接):\r\n- | - GBDT 主模块文件夹\r\n- | --- gbdt.py 梯度提升算法主框架\r\n- | --- decision_tree.py 单颗树生成,包括节点划分和叶子结点生成\r\n- | --- loss_function.py 损失函数\r\n- | --- tree_plot.py 树的可视化\r\n- | - example.py 回归/二分类/多分类测试文件\r\n\r\n\r\n- 二分类GBDT测试,运行如下命令:\r\n\r\n    `python example.py --model  binary_cf`\r\n\r\n- 还未增加约束的GBDT\r\n![](https://upload-images.jianshu.io/upload_images/11682271-4a19ac8ac0bb5ec8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n可见在原来的数据规律里面,age和标签是呈现正相关的,也就是age越高,标签越高。\r\n\r\n- 当我们在example.py中新增配置业务先验约束(令age需要和标签呈负相关)的GBDT。此时,在本实验数据集age特征的各分裂点可能都是不符合业务逻辑,都没有选用,如下运行结果:\r\n```\r\ndef run(args):\r\n    ### 配置特征业务逻辑性得约束###\r\n    feas_logit = {'age': -1}\r\n    ### 配置end###\r\n```\r\n![](https://upload-images.jianshu.io/upload_images/11682271-ddbe5ce579902a90.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n个人实践经验,当加入的业务先验比较合理的情况,模型泛化(测试集)误差可能会更低(训练集的误差通常会增加),或者训练-测试两者差异更小了。模型有更好的泛化能力。有兴趣的童鞋可以在更大数据集里面试验下,以便更客观地评估下加入业务约束的模型效果差异。\r\n\r\n\u003e参考链接\r\nGBDT算法原理以及实例理解(含代码):https://blog.csdn.net/zpalyq110/article/details/79527653\r\n","author":{"url":"https://github.com/aialgorithm","@type":"Person","name":"aialgorithm"},"datePublished":"2022-11-02T03:39:40.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/61/Blog/issues/61"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d437f2d5-1369-e816-d9ff-8b1638ba9ef2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDB2A:284E5C:224BB9D:2F06F98:696AC22D
html-safe-nonce79f5425eaa5997d4fd08cce4f5edf4e32867c283377fbf67ea96861f6c6d77b5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjJBOjI4NEU1QzoyMjRCQjlEOjJGMDZGOTg6Njk2QUMyMkQiLCJ2aXNpdG9yX2lkIjoiNTAxNjU5NzkzMTc5MTkyNTgwNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac7245510b6a495a921be04e9c3b98f0f3766b997c95ca9fa4d0515ac4469b8f0a
hovercard-subject-tagissue:1432431783
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/aialgorithm/Blog/61/issue_layout
twitter:imagehttps://opengraph.githubassets.com/138c954afba02464f36918d4a7d9ae44e0a681a784e2a46a8582fb020a2ef14e/aialgorithm/Blog/issues/61
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/138c954afba02464f36918d4a7d9ae44e0a681a784e2a46a8582fb020a2ef14e/aialgorithm/Blog/issues/61
og:image:alt一、模型解释性的意义 机器学习业务应用以输出决策判断为目标。可解释性是指人类能够理解决策原因的程度。机器学习模型的可解释性越高,人们就越容易理解为什么做出某些决定或预测。模型可解释性指对模型内部机制的理解以及对模型结果的理解。其重要性体现在:建模阶段,辅助开发人员理解模型,进行模型的对比选择,必要时优化调整模型;在投入运行阶段,向业务方解释模型的内部机制,对模型结果进行解释。比如基金推荐模型...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaialgorithm
hostnamegithub.com
expected-hostnamegithub.com
None986b6a1d774985095564e64d6963d11f094da3d0e2bfda2ab1a27d63662eb033
turbo-cache-controlno-preview
go-importgithub.com/aialgorithm/Blog git https://github.com/aialgorithm/Blog.git
octolytics-dimension-user_id33707637
octolytics-dimension-user_loginaialgorithm
octolytics-dimension-repository_id147093233
octolytics-dimension-repository_nwoaialgorithm/Blog
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id147093233
octolytics-dimension-repository_network_root_nwoaialgorithm/Blog
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release89ad2112b9c4e11df6a0c13c8c1f8eedd36b0977
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/aialgorithm/Blog/issues/61#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faialgorithm%2FBlog%2Fissues%2F61
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faialgorithm%2FBlog%2Fissues%2F61
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=aialgorithm%2FBlog
Reloadhttps://github.com/aialgorithm/Blog/issues/61
Reloadhttps://github.com/aialgorithm/Blog/issues/61
Reloadhttps://github.com/aialgorithm/Blog/issues/61
aialgorithm https://github.com/aialgorithm
Bloghttps://github.com/aialgorithm/Blog
Notifications https://github.com/login?return_to=%2Faialgorithm%2FBlog
Fork 259 https://github.com/login?return_to=%2Faialgorithm%2FBlog
Star 942 https://github.com/login?return_to=%2Faialgorithm%2FBlog
Code https://github.com/aialgorithm/Blog
Issues 66 https://github.com/aialgorithm/Blog/issues
Pull requests 0 https://github.com/aialgorithm/Blog/pulls
Actions https://github.com/aialgorithm/Blog/actions
Projects 0 https://github.com/aialgorithm/Blog/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/aialgorithm/Blog/security
Please reload this pagehttps://github.com/aialgorithm/Blog/issues/61
Insights https://github.com/aialgorithm/Blog/pulse
Code https://github.com/aialgorithm/Blog
Issues https://github.com/aialgorithm/Blog/issues
Pull requests https://github.com/aialgorithm/Blog/pulls
Actions https://github.com/aialgorithm/Blog/actions
Projects https://github.com/aialgorithm/Blog/projects
Security https://github.com/aialgorithm/Blog/security
Insights https://github.com/aialgorithm/Blog/pulse
New issuehttps://github.com/login?return_to=https://github.com/aialgorithm/Blog/issues/61
New issuehttps://github.com/login?return_to=https://github.com/aialgorithm/Blog/issues/61
引入业务先验约束的树模型(Python)https://github.com/aialgorithm/Blog/issues/61#top
https://github.com/aialgorithm
https://github.com/aialgorithm
aialgorithmhttps://github.com/aialgorithm
on Nov 2, 2022https://github.com/aialgorithm/Blog/issues/61#issue-1432431783
https://camo.githubusercontent.com/7c533bc3e5dace7e44e129b6b23c89fb27775536fce633b2074645bbd32478c2/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d613265616265303862623532383832362e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
一文梳理金融风控建模全流程(Python)https://mp.weixin.qq.com/s?__biz=MzI4MDE1NjExMQ==&mid=2247489574&idx=1&sn=98ca40dd2775428963b50a05e3a1f06c&chksm=ebbd9a86dcca1390c85fe18b330db1f8c0458a783a8d327c65a74fbcb38f2b72390dc64c4fe2&scene=178&cur_album_id=1986073923821551618#rd
一个简单的剪枝调整业务解释性的方法https://mp.weixin.qq.com/s/K5RwETMk4S7XmHKkTFxrmg
https://camo.githubusercontent.com/ccf47c42aa9a4565d5018665de2b1c8ee45bd84d7b3b7de7e7c266d5cd832f19/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d646134613433306637656234636266362e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
Graphviz官网https://graphviz.gitlab.io/_pages/Download/Download_windows.html
https://camo.githubusercontent.com/e3a2e2e40f98ccdd5b575e4c7cb38b74c5aae56a66b93deb86b5dcb9bd0699a9/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d346131396163386163306262356563382e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/16e866f30323fe388d4090f16b320d20fdf850777651ded3119f455917f384e2/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d646462653563653537393930326139302e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://blog.csdn.net/zpalyq110/article/details/79527653https://blog.csdn.net/zpalyq110/article/details/79527653
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.