1. LGBM回归任务代码

import numpy as np
import lightgbm as lgbm
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
from sklearn.datasets import make_regression
import nnidef load_data(): # 这个用来读取数据reg_x, reg_y = make_regression(n_samples=1000, n_features=5)x_train, x_test, y_train, y_test = train_test_split(reg_x, reg_y, train_size=0.8, random_state=0, shuffle=True)return x_train, y_train, x_test, y_testdef get_model(param, x_train, y_train, x_test, y_test): # 这个用来计算结果,并报告给NNI框架model = lgbm.LGBMRegressor(**param)model.fit(x_train, np.array(y_train), eval_set=[(x_test, np.array(y_test))], early_stopping_rounds=100, verbose=-1)value = float(mean_squared_error(y_test, model.predict(x_test)))  # 注意这里只能是int,float类型,不能是numpy,ndarry这种类型nni.report_final_result(value)if __name__ == '__main__':RECEIVED_PARAMS = nni.get_next_parameter() # 得到框架返回的参数params = {'num_leaves': 120,'min_data_in_leaf': 60,'objective': 'regression','max_depth': -1,'learning_rate': 0.08,"min_child_samples": 40,"boosting": "gbdt","feature_fraction": 0.95, } # 初始参数x_train, y_train, x_test, y_test = load_data()params.update(RECEIVED_PARAMS) # 用框架的新参数,更新初始参数model = lgbm.LGBMRegressor(**params) # 建模get_model(params, x_train, y_train, x_test, y_test)  # 得到结果

2. 配置search_space.json

这个文件用来配置参数的调节范围:

{"num_leaves":{"_type":"randint","_value":[ 20,50 ]},"learning_rate":{"_type":"uniform","_value":[0.05 , 0.5 ]},"n_estimators":{"_type":"randint","_value":[ 50 , 200 ]},"min_child_samples":{"_type":"randint","_value":[ 5, 30 ]}
}

3. 配置config.yml

这是框架的配置文件

新建一个config.yml文件,写入:

searchSpaceFile: search_space.json # 这是参数空间,文件名匹配就行
trialCommand: python my_nni_lgbm.py # 这是python文件,文件名匹配就行
trialConcurrency: 10 # 同步进行10轮调参
maxTrialNumber: 10000 # 自动调参10000次
maxExperimentDuration: 8h # 持续8小时
tuner:name: TPEclassArgs:optimize_mode: minimize
trainingService: # For other platforms, check mnist-pytorch exampleplatform: local

然后在控制台运行:

nnictl create --config config.yml -p 12387

看到执行成功的日志:

INFO:  Starting restful server...
INFO:  Successfully started Restful server!
INFO:  Starting experiment...
INFO:  Successfully started experiment!
------------------------------------------------------------------------------------
The experiment id is me5YV9Q8
The Web UI urls are: http://127.0.0.1:12387   http://10.8.74.190:12387
------------------------------------------------------------------------------------You can use these commands to get more information about the experiment
------------------------------------------------------------------------------------commands                       description
1. nnictl experiment show        show the information of experiments
2. nnictl trial ls               list all of trial jobs
3. nnictl top                    monitor the status of running experiments
4. nnictl log stderr             show stderr log content
5. nnictl log stdout             show stdout log content
6. nnictl stop                   stop an experiment
7. nnictl trial kill             kill a trial job by id
8. nnictl --help                 get help information about nnictl
------------------------------------------------------------------------------------
Command reference document https://nni.readthedocs.io/en/latest/Tutorial/Nnictl.html
------------------------------------------------------------------------------------

访问本机:http://127.0.0.1:12387 ,就可以看到成功执行的界面:

自动化调参NNI学习(二):使用NNI框架调整LGBM模型相关推荐

  1. 深度学习调参体验(二)

    深度学习调参体验(二) 激活函数选择: 常用的激活函数有relu.leaky-relu.sigmoid.tanh等.对于输出层,多分类任务选用softmax输出,二分类任务选用sigmoid输出,回归 ...

  2. 机器学习狗太苦逼了!自动化调参哪家强?

    机器学习狗太苦逼了!自动化调参哪家强? https://mp.weixin.qq.com/s/gqN0fDIJBoxyAxYaC2dI-w 作者|Facundo Santiago译者|李志编辑|Deb ...

  3. 自动化调参NNI学习(三):使用python启动NNI框架调整随机森林(RandomForest)模型

    首先按照NNI框架的要求写一个调参的代码文件my_rf.py: import nni from sklearn.model_selection import train_test_split impo ...

  4. XGBoost调参技巧(二)Titanic实战Top9%

    学习Kaggle的第一个比赛就是Titanic,断断续续的半年时间,从小白到杀入9%.XGBoost果真是Kaggle杀器,帮我在Titanic中进入9%.zillow进入22%. 简介 Titani ...

  5. [自动调参]深度学习模型的超参数自动化调优详解

    向AI转型的程序员都关注了这个号

  6. spring boot 学习(二)spring boot 框架整合 thymeleaf

    spring boot 框架整合 thymeleaf spring boot 的官方文档中建议开发者使用模板引擎,避免使用 JSP.因为若一定要使用 JSP 将无法使用. 注意:本文主要参考学习了大神 ...

  7. 二、CI框架之MCV模型

    一.关于MCV,大概就是下图所示: 模型(model)-视图(view)-控制器(controller) M用来处理数据库,V用来显示界面,C用来控制 二.对应到CI的源码,对应的是这3个目录 转载于 ...

  8. #####好好好####从Google Visor到Microsoft NNI再到Advisor调参服务接口发展史

    从Google Visor到Microsoft NNI再到Advisor调参服务接口发展史 tobe Contributor to the world. 10 人赞了该文章 介绍 从规则编程到机器学习 ...

  9. 使用NNI,从此告别手动调参

    一.前言 最近在朋友的介绍下,了解了一个神经网络的调参神器--微软开发的NNI (Neural Network Intelligence),在经过简单尝试之后,发现是真的香.倘若你也苦于每次炼丹都要手 ...

最新文章

  1. 2、使用rpm包安装grafana
  2. 基于jquery,bootstrap数据验证插件bootstrapValidator 教程
  3. 22 岁专访库克、B 站 3 天涨粉百万,他将毕设树莓派扫描仪升级,繁星散落在校空!...
  4. rpm包安装mysql5.5
  5. 【VBA研究】怎样将单元格数据赋给数组
  6. markdown 公式_【建议收藏】数学公式如何用Markdown优雅地写出来
  7. [html] 如何阻止屏幕旋转时自动调整字体的大小?
  8. lucene索引创建
  9. 笨方法“学习python笔记之元组(tuple)
  10. 下月上市!中兴AXON 10 Pro 5G版通过3C认证 加入5G大战
  11. logback日志pattern_Springboot整合log4j2日志全解
  12. 使用ld的wrap选项替换已有库函数
  13. 系统分析与设计第一次作业
  14. 【MySQL 8.0】导入 .frm .MYD .MYI
  15. android 支付宝私钥加密,支付宝支付密钥RSA1升级到RSA2
  16. c语言实现动画的方法,C语言动画技术的实现方法
  17. GGSN与SGSN简介
  18. c++和python哪个好_python和c++哪个好 有什么区别
  19. Javaweb开发一般步骤
  20. 中国探月计算机考试时间,揭秘人类探月历程(组图)

热门文章

  1. 计算机多媒体专业是什么专业,什么是计算机多媒体技术
  2. 子集和问题 算法_贪婪算法有多好?Submodularity告诉你
  3. HAProxy反向代理搭建discuz论坛
  4. Sonar6.0应用之四:与Jenkins集成分析(Scanner+Maven)
  5. 【20160924】GOCVHelper MFC增强算法(2)
  6. android --- fastboot 协议学习
  7. 简述一下索引的匹配原则_Mysql联合索引最左匹配原则
  8. springboot内置浏览器_SpringBoot快速搭建
  9. Docker之Docker网络讲解
  10. Zookeeper之Watcher机制详解