# -*- coding: utf-8 -*-
import time
import numpy as np
from sklearn.datasets import load_digits
from sklearn.ensemble import RandomForestClassifier
from sklearn.grid_search import GridSearchCV
from sklearn.grid_search import RandomizedSearchCV# 生成数据
digits = load_digits()
X, y = digits.data, digits.target# 元分类器
meta_clf = RandomForestClassifier(n_estimators=20)# =================================================================
# 设置参数
param_dist = {"max_depth": [3, None],"max_features": [1,5,7,11],"min_samples_split": [1,5,7,11],"min_samples_leaf": [1,5,7,11],"bootstrap": [True, False],"criterion": ["gini", "entropy"]}# 运行随机搜索 RandomizedSearch
n_iter_search = 20
rs_clf = RandomizedSearchCV(meta_clf, param_distributions=param_dist,n_iter=n_iter_search)start = time.time()
rs_clf.fit(X, y)
print("RandomizedSearchCV took %.2f seconds for %d candidates parameter settings." % ((time.time() - start), n_iter_search))
print(rs_clf.grid_scores_)# =================================================================
# 设置参数
param_grid = {"max_depth": [3, None],"max_features": [1, 3, 10],"min_samples_split": [1, 3, 10],"min_samples_leaf": [1, 3, 10],"bootstrap": [True, False],"criterion": ["gini", "entropy"]}# 运行网格搜索 GridSearch
gs_clf = GridSearchCV(meta_clf, param_grid=param_grid)
start = time.time()
gs_clf.fit(X, y)print("GridSearchCV took %.2f seconds for %d candidate parameter settings." % (time.time() - start, len(gs_clf.grid_scores_)))
print(gs_clf.grid_scores_)

RandomizedSearchCV 和GridSearchCV相关推荐

  1. sklearn支持gpu_Keras Sklearn随机搜索GPU OOM

    我想将RandomizedSearchCV(或GridSearchCV)应用到我的Keras模型(TensorFlow后端).但是,经过多次不同超参数集的训练,出现了OOM错误.在 下面是我的代码和错 ...

  2. 《Hands-On Machine Learning with Scikit-Learn TensorFlow》读书笔记(二):端到端的机器学习

    最近有时间看书了,把以前想看的书捡一下,翻译中顺便加上自己的理解,写个读书笔记. 假装最近聘请了一家房地产公司的数据科学家,然后通过一个示例项目,从头至尾了解机器学习. 以下是要完成的主要步骤: 查看 ...

  3. 机器学习算法基本工作流程

    数据科学家 - 主要步骤 观察大局 获得数据 从数据探索和可视化中获得洞见 机器学习算法的数据准备 选择和训练模型 微调模型 展示解决方案 启动.监控和维护系统 观察大局 获取明确的目标任务 明确目标 ...

  4. 基于Python的医疗花费预测

    资源下载地址:https://download.csdn.net/download/sheziqiong/85837039 资源下载地址:https://download.csdn.net/downl ...

  5. 机器学习预测价格低点_使用机器学习技术预测机票价格

    机器学习预测价格低点 Travelling is one of the most entertaining things that everybody wants to avoid city crow ...

  6. GridSearchCV与RandomizedSearchCV

    RandomizedSearchCV使用案例: #Loading libraries import pandas as pd import numpy as np pd.options.display ...

  7. GridSearchCV和RandomizedSearchCV调参

    1 GridSearchCV实际上可以看做是for循环输入一组参数后再比较哪种情况下最优. 使用GirdSearchCV模板 # Use scikit-learn to grid search the ...

  8. 使用GridSearchCV和RandomizedSearchCV进行超参数调整

    In Machine Learning, a hyperparameter is a parameter whose value is used to control the learning pro ...

  9. GridSearchCV和RandomizedSearchCV(以SVM为例)

    GridSearchCV参考代码 CC = []gammas = []for i in range(-5, 16, 2):CC.append(2 ** i)for i in range(3, -16, ...

最新文章

  1. 5.JasperReports学习笔记5-其它数据生成动态的报表(WEB)
  2. 提升Visual Studio 2012的响应能力
  3. opencv 车辆识别_丽水专业人脸自动识别系统网
  4. linux能远程开机么,Linux 下如何实现远程开机
  5. Angular ng-content元素的学习笔记
  6. 都匀中专学计算机,都匀计算机专业中专学校学几年
  7. 【问题3】生产环境中的 redis 是怎么部署的?
  8. 聚类分析软件测试,基于复杂网络的软件测试路径聚类分析-计算机工程与应用.PDF...
  9. Excel小问题 - 前三个非空单元格数值之和
  10. guava-retry介绍
  11. 写一篇简单的微信接入
  12. 图像的指纹——从自然图片到GAN
  13. 转~~前端轮播 简单实现 啵啵啵!!!
  14. latex如何设置字体并加粗_Latex设置字体大小,加粗,加下划线,变斜体_孩纸气_新浪博客...
  15. Android CameraX的PreviewView Ar背景实景实时预览
  16. linux线程详解:线程概念、线程调度、线程安全、线程模型
  17. python平安经_读完一本平安经是怎样的体验?
  18. MTK-call history operate
  19. 支付宝html页面乱码,如何处理支付宝支付后端返回的html代码
  20. Nginx集成GeoIP2模块实现地区识别与屏蔽

热门文章

  1. Python3道基础练习题
  2. python线程join
  3. Python内置函数查询表——总结篇
  4. android如何设置多条广播,Android使用MulticastSocket实现多点广播图片
  5. java句子中找单词_java程序找到一个句子中每个单词的字母数
  6. source环境变量命令千万不能乱用
  7. iostat 命令查看linux磁盘I/O
  8. promise ajax 队列,ES6中的promise,从使用promise封装ajax说起
  9. python中 和is的区别_关于python中的is和==的区别
  10. 深度解析HashMap高频面试及底层实现架构!