René's URL Explorer Experiment


Title: 机器学习模型迭代方法(总结) · Issue #60 · aialgorithm/Blog · GitHub

Open Graph Title: 机器学习模型迭代方法(总结) · Issue #60 · aialgorithm/Blog

X Title: 机器学习模型迭代方法(总结) · Issue #60 · aialgorithm/Blog

Description: 模型迭代方法 机器学习模型在实际应用的场景,通常要根据新增的数据下进行模型的迭代,常见的模型迭代方法有以下几种: 1、全量数据重新训练一个模型,直接合并历史训练数据与新增的数据,模型直接离线学习全量数据,学习得到一个全新的模型。 优缺点:这也是实际最为常见的模型迭代方式,通常模型效果也是最好的,但这样模型迭代比较耗时,资源耗费比较多,实时性较差,特别是在大数据场景更为困难; 2、模型融合的方法,将旧模型的预测结果作为一个新增特征,在新的数据上面训练一个新的模型;优缺点:...

Open Graph Description: 模型迭代方法 机器学习模型在实际应用的场景,通常要根据新增的数据下进行模型的迭代,常见的模型迭代方法有以下几种: 1、全量数据重新训练一个模型,直接合并历史训练数据与新增的数据,模型直接离线学习全量数据,学习得到一个全新的模型。 优缺点:这也是实际最为常见的模型迭代方式,通常模型效果也是最好的,但这样模型迭代比较耗时,资源耗费比较多,实时性较差,特别是在大数据场景更为困难; 2、模型融合的方...

X Description: 模型迭代方法 机器学习模型在实际应用的场景,通常要根据新增的数据下进行模型的迭代,常见的模型迭代方法有以下几种: 1、全量数据重新训练一个模型,直接合并历史训练数据与新增的数据,模型直接离线学习全量数据,学习得到一个全新的模型。 优缺点:这也是实际最为常见的模型迭代方式,通常模型效果也是最好的,但这样模型迭代比较耗时,资源耗费比较多,实时性较差,特别是在大数据场景更为困难; 2、模型融合的方...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"机器学习模型迭代方法(总结)","articleBody":"## 模型迭代方法\r\n机器学习模型在实际应用的场景,通常要根据新增的数据下进行模型的迭代,常见的模型迭代方法有以下几种:\r\n\r\n- 1、全量数据重新训练一个模型,直接合并历史训练数据与新增的数据,模型直接离线学习全量数据,学习得到一个全新的模型。 优缺点:这也是实际最为常见的模型迭代方式,通常模型效果也是最好的,但这样模型迭代比较耗时,资源耗费比较多,实时性较差,特别是在大数据场景更为困难;\r\n\r\n- 2、模型融合的方法,将旧模型的预测结果作为一个新增特征,在新的数据上面训练一个新的模型;优缺点:训练耗时较短了,增加决策的复杂度,新增数据量要足够多才能保证融合效果;\r\n\r\n- 3、增量(在线)学习的方法,如sklearn中算法可调用partial_fit直接增量学习,可以直接利用新增的数据在原来的模型的基础上做进一步更新。增量学习对于模型迭代是很有效率的(特别适用于神经网络的学习,如 arxiv.org/abs/1711.03705)。实际使用中,在线学习和离线的全量学习经常是结合使用,比如离线以全量数据训练一个复杂的模型,在线利用新增样本进行微调。优缺点:对内存友好,模型迭代快且效率较高;\r\n\r\n## 二、增量学习\r\n主流的几种机器学习框架,已经实现了增量学习的功能,像sklearn可以直接调用partial_fit做增量学习,神经网络增量学习也很方便,如下tensorflow.keras框架实现增量学习:\r\n```\r\n# tensorflow.keras增量学习\r\nmodel_path = 'init.model' #加载线上的原模型\r\nloaded_model = tf.keras.models.load_model(model_path)\r\n# 新数据上接着训练原模型\r\nhistory = loaded_model.fit(\r\n    train_data_gen,\r\n    epochs=epochs\r\n)\r\n```\r\n本文主要对树模型的增量(在线)学习展开介绍,如下以树模型lightgbm及xgboost增量学习金融违约的分类模型为例,验证实际的效果。\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开始之前,我们先把数据划分为训练集及测试集,测试集数据仅做评估。接着训练数据再划分为两部分:旧训练数据,新训练数据集。以此验证用增量学习方法进行学习新数据集的效果\r\n\r\n```\r\n# 划分数据集:训练集和测试集\r\ntrain_x, test_x, train_y, test_y = train_test_split(train_bank[num_feas + cate_feas], train_bank.isDefault,test_size=0.3, random_state=0)\r\n\r\n# 训练集再划分新旧的训练集,新的训练集用增量学习方法进行学习\r\ntrainold_x, trainnew_x, trainold_y, trainnew_y = train_test_split(train_x, train_y,test_size=0.5, random_state=0)\r\n\r\nlgb_train = lgb.Dataset(trainold_x, trainold_y)\r\nlgb_newtrain = lgb.Dataset(trainnew_x, trainnew_y)\r\nlgb_eval = lgb.Dataset(test_x,test_y, reference=lgb_train)\r\n\r\n```\r\n\r\n\r\n训练原始的lightgbm模型,评估模型效果还算不错:train  {'AUC': 0.8696629477540933, 'KS': 0.6470059543871476}\r\ntest  {'AUC': 0.8458304576799567, 'KS': 0.6284431987999525}\r\n```\r\n# 参数\r\nparams = {\r\n    'task': 'train',\r\n    'boosting_type': 'gbdt',  # 设置提升类型\r\n    'objective': 'binary',  # 目标函数\r\n    'metric': {'l2', 'auc'},  # 评估函数\r\n    'num_leaves': 12,  # 叶子节点数\r\n    'learning_rate': 0.05,  # 学习速率\r\n    'feature_fraction': 0.9,  # 建树的特征选择比例\r\n    'bagging_fraction': 0.8,  # 建树的样本采样比例\r\n    'verbose': 1  \r\n}\r\n \r\n# 模型训练\r\ngbm = lgb.train(params, lgb_train, num_boost_round=1)\r\n\r\nprint('train ',model_metrics(gbm,trainold_x, trainold_y))\r\nprint('test ',model_metrics(gbm,test_x,test_y))\r\n# 树模型决策的可视化\r\n\r\n\r\n# 需要先安装https://graphviz.org/download/\r\nimport os\r\nos.environ[\"PATH\"] += os.pathsep + 'D:/Program Files/Graphviz/bin/'\r\n\r\nfor k in range(1):\r\n    ax = lgb.plot_tree(gbm, tree_index=k, figsize=(30,20), show_info=['split_gain','internal_value','internal_count','internal_weight','leaf_count','leaf_weight','data_percentage'])\r\nplt.show()\r\n\r\n```\r\n打印出原始树模型的结构如下:\r\n![](https://upload-images.jianshu.io/upload_images/11682271-82a4dd78410cb752.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n接下来就是本文的重点了,增量学习新的lightgbm树模型,我们在原有gbm模型的基础上继续更新模型为gbm2。\r\n\r\n其实,lightgbm增量学习的更新方式其实就是原有模型的树结构都不变的基础上,继续添加学习一些树,比如如下代码我们会继续训练出2棵新的树,\r\n```\r\nnum_boost_round = 2  # 继续训练2颗树\r\ngbm2 = lgb.train(params,\r\n                lgb_newtrain,  #新的数据\r\n                num_boost_round=num_boost_round ,\r\n                init_model=gbm,             #在原模型gbm的基础上接着训练\r\n                verbose_eval=False,\r\n                keep_training_booster=True) # 支持模型增量训练\r\n\r\n```\r\n![](https://upload-images.jianshu.io/upload_images/11682271-e95944aa06c9d851.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n\r\n从增量学习后的树模型的结构,可以看出原有树模型gbm结构一点都没有变,只是再后面更新了2棵新的树。验证增量学习更新后的模型效果,测试集的auc是有提升1%左右的(注:本例无考虑调参下的效果差异,仅从效果来看是还不错的~)\r\n![](https://upload-images.jianshu.io/upload_images/11682271-fb35af533e7029ba.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n这时就有个疑问了,树模型的增量学习只有像类似“打补丁”的更新方式吗,不能通过更新下旧模型的叶子节点的权重?\r\n\r\n其实,这两种增量学习方法,树模型可以有的,但是对于lightgbm我没有找到支持的方法,有兴趣的同学可以再了解下。。如下为XGBOOST实现两种增量学习的方法\r\n```\r\n###  xgbooost 增量学习  https://xgboost.readthedocs.io/en/latest/parameter.html\r\nimport xgboost as xgb\r\nimport pprint\r\n\r\nxgb_params_01 = {}\r\n# 增量学习的方法一\r\nxgb_params_02 = {'process_type': 'default', # default, update\r\n                 'refresh_leaf': True}  # 当前迭代树的结构不变,并在此增加新树\r\n# 增量学习的方法二\r\nxgb_params_02 = {'process_type': 'update', # default, update\r\n                 'updater': 'refresh',  # 也可以选择再当前模型做剪枝\r\n                 'refresh_leaf': True}  # 仅重新更新模型的叶节点权重,\r\n\r\ndtrain_2class = xgb.DMatrix(train_x[num_feas], label=train_y,enable_categorical=True)\r\ngbdt = xgb.train(xgb_params_01, dtrain_2class, num_boost_round=1) # 旧模型\r\npprint.pprint(gbdt.get_dump())\r\ngbdt = xgb.train(xgb_params_02, dtrain_2class, num_boost_round=2, xgb_model=gbdt) # 更新模型\r\npprint.pprint(gbdt.get_dump())\r\n```\r\n\r\n\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/aialgorithm","@type":"Person","name":"aialgorithm"},"datePublished":"2022-11-02T03:39:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/60/Blog/issues/60"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e5316397-c344-5f85-9fe0-fac762606260
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD6B8:2F31CD:9B5E02:D6126C:6969EC7D
html-safe-nonce6b507bf3293a582f0ad7333f7350880c5792fb784f9138975ebd75bfafce7a1c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENkI4OjJGMzFDRDo5QjVFMDI6RDYxMjZDOjY5NjlFQzdEIiwidmlzaXRvcl9pZCI6IjY3NDUxNjU5ODMxNjE5MDQyNTMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac330a0ec30ee635f63363d537a58c1e61d2abb05065b3b7e625b0fb7bb8f5b78e
hovercard-subject-tagissue:1432431374
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/60/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e622c553d5c61efa3697474582e394ea81da5bc1c80813481113ca8e9d2a4cfb/aialgorithm/Blog/issues/60
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e622c553d5c61efa3697474582e394ea81da5bc1c80813481113ca8e9d2a4cfb/aialgorithm/Blog/issues/60
og:image:alt模型迭代方法 机器学习模型在实际应用的场景,通常要根据新增的数据下进行模型的迭代,常见的模型迭代方法有以下几种: 1、全量数据重新训练一个模型,直接合并历史训练数据与新增的数据,模型直接离线学习全量数据,学习得到一个全新的模型。 优缺点:这也是实际最为常见的模型迭代方式,通常模型效果也是最好的,但这样模型迭代比较耗时,资源耗费比较多,实时性较差,特别是在大数据场景更为困难; 2、模型融合的方...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaialgorithm
hostnamegithub.com
expected-hostnamegithub.com
None7b32f1c7c4549428ee399213e8345494fc55b5637195d3fc5f493657579235e8
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
releasebdde15ad1b403e23b08bbd89b53fbe6bdf688cad
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/aialgorithm/Blog/issues/60#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faialgorithm%2FBlog%2Fissues%2F60
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%2F60
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/60
Reloadhttps://github.com/aialgorithm/Blog/issues/60
Reloadhttps://github.com/aialgorithm/Blog/issues/60
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/60
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/60
New issuehttps://github.com/login?return_to=https://github.com/aialgorithm/Blog/issues/60
机器学习模型迭代方法(总结)https://github.com/aialgorithm/Blog/issues/60#top
https://github.com/aialgorithm
https://github.com/aialgorithm
aialgorithmhttps://github.com/aialgorithm
on Nov 2, 2022https://github.com/aialgorithm/Blog/issues/60#issue-1432431374
一文梳理金融风控建模全流程(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://camo.githubusercontent.com/3e1d8a1e4d9642b22b41333aee59288df185ddd3629b286535d5d538a0dc95d4/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d383261346464373834313063623735322e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/03c7dad1b631b5098227dc0f84e13540c9c4b22b588b25a6acb5f0ee97a667a8/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d653935393434616130366339643835312e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/41bb3121378b98a4464a16064b4a8ae3335e109d732e0eca4798fc8fbd42befd/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d666233356166353333653730323962612e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
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.