René's URL Explorer Experiment


Title: 一文归纳Ai调参炼丹之法 · Issue #12 · aialgorithm/Blog · GitHub

Open Graph Title: 一文归纳Ai调参炼丹之法 · Issue #12 · aialgorithm/Blog

X Title: 一文归纳Ai调参炼丹之法 · Issue #12 · aialgorithm/Blog

Description: 1 超参数优化 调参即超参数优化,是指从超参数空间中选择一组合适的超参数,以权衡好模型的偏差(bias)和方差(variance),从而提高模型效果及性能。常用的调参方法有: 人工手动调参 网格/随机搜索(Grid / Random Search) 贝叶斯优化(Bayesian Optimization) 注:超参数 vs 模型参数差异 超参数是控制模型学习过程的(如网络层数、学习率); 模型参数是通过模型训练学习后得到的(如网络最终学习到的权重值)。 2 人工调参 手...

Open Graph Description: 1 超参数优化 调参即超参数优化,是指从超参数空间中选择一组合适的超参数,以权衡好模型的偏差(bias)和方差(variance),从而提高模型效果及性能。常用的调参方法有: 人工手动调参 网格/随机搜索(Grid / Random Search) 贝叶斯优化(Bayesian Optimization) 注:超参数 vs 模型参数差异 超参数是控制模型学习过程的(如网络层数、学习率); 模...

X Description: 1 超参数优化 调参即超参数优化,是指从超参数空间中选择一组合适的超参数,以权衡好模型的偏差(bias)和方差(variance),从而提高模型效果及性能。常用的调参方法有: 人工手动调参 网格/随机搜索(Grid / Random Search) 贝叶斯优化(Bayesian Optimization) 注:超参数 vs 模型参数差异 超参数是控制模型学习过程的(如网络层数、学习率); 模...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"一文归纳Ai调参炼丹之法","articleBody":"# 1 超参数优化\r\n![](https://upload-images.jianshu.io/upload_images/11682271-74c8d04000774d9f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n调参即超参数优化,是指从超参数空间中选择一组合适的超参数,以权衡好模型的偏差(bias)和方差(variance),从而提高模型效果及性能。常用的调参方法有:\r\n- 人工手动调参\r\n- 网格/随机搜索(Grid / Random Search)\r\n- 贝叶斯优化(Bayesian Optimization)\r\n\r\n\r\n![](https://upload-images.jianshu.io/upload_images/11682271-ed35aeb28f2e58bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\u003e注:超参数 vs 模型参数差异\r\n超参数是控制模型学习过程的(如网络层数、学习率);\r\n模型参数是通过模型训练学习后得到的(如网络最终学习到的权重值)。\r\n\r\n\r\n# 2  人工调参\r\n\r\n手动调参需要结合数据情况及算法的理解,优化调参的优先顺序及参数的经验值。\r\n\r\n不同模型手动调参思路会有差异,如随机森林是一种bagging集成的方法,参数主要有n_estimators(子树的数量)、max_depth(树的最大生长深度)、max_leaf_nodes(最大叶节点数)等。(此外其他参数不展开说明)\r\n对于n_estimators:通常越大效果越好。参数越大,则参与决策的子树越多,可以消除子树间的随机误差且增加预测的准度,以此降低方差与偏差。\r\n对于max_depth或max_leaf_nodes:通常对效果是先增后减的。取值越大则子树复杂度越高,偏差越低但方差越大。\r\n\r\n![](https://upload-images.jianshu.io/upload_images/11682271-3d8d5d3e0a3fc8ec.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n\r\n# 3 网格/随机搜索\r\n![](https://upload-images.jianshu.io/upload_images/11682271-2bcf7159ed14706d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n\r\n- 网格搜索(grid search),是超参数优化的传统方法,是对超参数组合的子集进行穷举搜索,找到表现最佳的超参数子集。\r\n- 随机搜索(random search),是对超参数组合的子集简单地做固定次数的随机搜索,找到表现最佳的超参数子集。对于规模较大的参数空间,采用随机搜索往往效率更高。\r\n\r\n```\r\nimport numpy as np\r\nfrom sklearn.model_selection import GridSearchCV\r\nfrom sklearn.model_selection import RandomizedSearchCV\r\nfrom sklearn.ensemble import RandomForestClassifier\r\n\r\n# 选择模型 \r\nmodel = RandomForestClassifier()\r\n# 参数搜索空间\r\nparam_grid = {\r\n    'max_depth': np.arange(1, 20, 1),\r\n    'n_estimators': np.arange(1, 50, 10),\r\n    'max_leaf_nodes': np.arange(2, 100, 10)\r\n\r\n}\r\n# 网格搜索模型参数\r\ngrid_search = GridSearchCV(model, param_grid, cv=5, scoring='f1_micro')\r\ngrid_search.fit(x, y)\r\nprint(grid_search.best_params_)\r\nprint(grid_search.best_score_)\r\nprint(grid_search.best_estimator_)\r\n# 随机搜索模型参数\r\nrd_search = RandomizedSearchCV(model, param_grid, n_iter=200, cv=5, scoring='f1_micro')\r\nrd_search.fit(x, y)\r\nprint(rd_search.best_params_)\r\nprint(rd_search.best_score_)\r\nprint(rd_search.best_estimator_)\r\n```\r\n\r\n# 4 贝叶斯优化\r\n贝叶斯优化(Bayesian Optimization)与网格/随机搜索最大的不同,在于考虑了历史调参的信息,使得调参更有效率。(高维参数空间下,贝叶斯优化复杂度较高,效果会近似随机搜索。)\r\n\r\n![](https://upload-images.jianshu.io/upload_images/11682271-bd6487e26f0b1601.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n## 4.1 算法简介\r\n贝叶斯优化思想简单可归纳为两部分:\r\n- 高斯过程(GP):以历史的调参信息(Observation)去学习目标函数的后验分布(Target)的过程。\r\n\r\n- 采集函数(AC): 由学习的目标函数进行采样评估,分为两种过程: 1、开采过程:在最可能出现全局最优解的参数区域进行采样评估。 2、勘探过程:兼顾不确定性大的参数区域的采样评估,避免陷入局部最优。\r\n\r\n## 4.2 算法流程\r\n```\r\nfor循环n次迭代:\r\n    采集函数依据学习的目标函数(或初始化)给出下个开采极值点 Xn+1;\r\n    评估Xn+1得到Yn+1;\r\n    加入新的Xn+1、Yn+1数据样本,并更新高斯过程模型;\r\n```\r\n\r\n![](https://upload-images.jianshu.io/upload_images/11682271-3cf2b807343709a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\r\n\r\n\r\n```\r\n\"\"\"\r\n随机森林分类Iris使用贝叶斯优化调参\r\n\"\"\"\r\nimport numpy as np\r\nfrom hyperopt import hp, tpe, Trials, STATUS_OK, Trials, anneal\r\nfrom functools import partial\r\nfrom hyperopt.fmin import fmin\r\nfrom sklearn.metrics import f1_score\r\nfrom sklearn.ensemble import RandomForestClassifier\r\n\r\ndef model_metrics(model, x, y):\r\n    \"\"\" 评估指标 \"\"\"\r\n    yhat = model.predict(x)\r\n    return  f1_score(y, yhat,average='micro')\r\n\r\ndef bayes_fmin(train_x, test_x, train_y, test_y, eval_iters=50):\r\n    \"\"\"\r\n    bayes优化超参数\r\n    eval_iters:迭代次数\r\n    \"\"\"\r\n    \r\n    def factory(params):\r\n        \"\"\"\r\n        定义优化的目标函数\r\n        \"\"\"\r\n        fit_params = {\r\n            'max_depth':int(params['max_depth']),\r\n            'n_estimators':int(params['n_estimators']),\r\n            'max_leaf_nodes': int(params['max_leaf_nodes'])\r\n            }\r\n        # 选择模型\r\n        model = RandomForestClassifier(**fit_params)\r\n        model.fit(train_x, train_y)\r\n        # 最小化测试集(- f1score)为目标\r\n        train_metric = model_metrics(model, train_x, train_y)\r\n        test_metric = model_metrics(model, test_x, test_y)\r\n        loss = - test_metric\r\n        return {\"loss\": loss, \"status\":STATUS_OK}\r\n\r\n    # 参数空间\r\n    space = {\r\n        'max_depth': hp.quniform('max_depth', 1, 20, 1),\r\n        'n_estimators': hp.quniform('n_estimators', 2, 50, 1), \r\n        'max_leaf_nodes': hp.quniform('max_leaf_nodes', 2, 100, 1)\r\n            }\r\n    # bayes优化搜索参数\r\n    best_params = fmin(factory, space, algo=partial(anneal.suggest,), max_evals=eval_iters, trials=Trials(),return_argmin=True)\r\n    # 参数转为整型\r\n    best_params[\"max_depth\"] = int(best_params[\"max_depth\"])\r\n    best_params[\"max_leaf_nodes\"] = int(best_params[\"max_leaf_nodes\"])\r\n    best_params[\"n_estimators\"] = int(best_params[\"n_estimators\"])\r\n    return best_params\r\n\r\n#  搜索最优参数\r\nbest_params = bayes_fmin(train_x, test_x, train_y, test_y, 100)\r\nprint(best_params)\r\n\r\n```\r\n---\r\n\r\n公众号**阅读原文**可访问[Github源码](https://github.com/aialgorithm/Blog/tree/master/projects/%E4%B8%80%E6%96%87%E5%BD%92%E7%BA%B3Ai%E8%B0%83%E5%8F%82%E7%82%BC%E4%B8%B9%E4%B9%8B%E6%B3%95)","author":{"url":"https://github.com/aialgorithm","@type":"Person","name":"aialgorithm"},"datePublished":"2021-03-05T09:11:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/12/Blog/issues/12"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:d18c8078-39ea-52bf-1713-cfad6d392028
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id90DA:16E0FE:1E5F4B3:2A693E2:696A56F7
html-safe-noncee4ed302517e5f251626d24d5b0b1f4478b553ee9f498c0c78acffb54c3f26260
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MERBOjE2RTBGRToxRTVGNEIzOjJBNjkzRTI6Njk2QTU2RjciLCJ2aXNpdG9yX2lkIjoiMzgxMjcxMjcwNjAyNzk2ODI0NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac29eae9ae29dd37b9b376537090c1b2a7b6c11f571a129f127658edb63529f48c
hovercard-subject-tagissue:822898642
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/12/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ba324e7003b71944fb41ef218f7c6d17b3974cea4a1061748328d88d27fbf434/aialgorithm/Blog/issues/12
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ba324e7003b71944fb41ef218f7c6d17b3974cea4a1061748328d88d27fbf434/aialgorithm/Blog/issues/12
og:image:alt1 超参数优化 调参即超参数优化,是指从超参数空间中选择一组合适的超参数,以权衡好模型的偏差(bias)和方差(variance),从而提高模型效果及性能。常用的调参方法有: 人工手动调参 网格/随机搜索(Grid / Random Search) 贝叶斯优化(Bayesian Optimization) 注:超参数 vs 模型参数差异 超参数是控制模型学习过程的(如网络层数、学习率); 模...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameaialgorithm
hostnamegithub.com
expected-hostnamegithub.com
None3f871c8e07f0ae1886fa8dac284166d28b09ad5bada6476fc10b674e489788ef
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
release63c426b30d262aba269ef14c40e3c817b384cd61
ui-targetcanary-1
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/aialgorithm/Blog/issues/12#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Faialgorithm%2FBlog%2Fissues%2F12
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%2F12
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/12
Reloadhttps://github.com/aialgorithm/Blog/issues/12
Reloadhttps://github.com/aialgorithm/Blog/issues/12
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/12
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/12
New issuehttps://github.com/login?return_to=https://github.com/aialgorithm/Blog/issues/12
一文归纳Ai调参炼丹之法https://github.com/aialgorithm/Blog/issues/12#top
https://github.com/aialgorithm
https://github.com/aialgorithm
aialgorithmhttps://github.com/aialgorithm
on Mar 5, 2021https://github.com/aialgorithm/Blog/issues/12#issue-822898642
https://camo.githubusercontent.com/219748089133ba32a62a11d4f7dbbb9cd6ced5df4ebd46fc57921af433e675d1/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d373463386430343030303737346439662e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/14d070ce02c85f55472166e0dd63286c4f5f299a3405b97920532d513222c1dc/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d656433356165623238663265353862632e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/a241d37a53a729745943be6830e401ec8fea7a168cded560a9aef7eae27f4ddd/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d336438643564336530613366633865632e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/2d4229fd89ea5a1040f8c0c1170511a9d46f005cfbb49f873a74275624110db3/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d326263663731353965643134373036642e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/01632bc266eb678c943fc0b679e5d327d0569c183ef01ff73ba1d35857156b62/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d626436343837653236663062313630312e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
https://camo.githubusercontent.com/12858d4fa1b8988b180155494d7f3381d57bd752bac7d50df4a2e85281ce4248/68747470733a2f2f75706c6f61642d696d616765732e6a69616e7368752e696f2f75706c6f61645f696d616765732f31313638323237312d336366326238303733343337303961362e706e673f696d6167654d6f6772322f6175746f2d6f7269656e742f7374726970253743696d61676556696577322f322f772f31323430
Github源码https://github.com/aialgorithm/Blog/tree/master/projects/%E4%B8%80%E6%96%87%E5%BD%92%E7%BA%B3Ai%E8%B0%83%E5%8F%82%E7%82%BC%E4%B8%B9%E4%B9%8B%E6%B3%95
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.