很多机器学习算法有参数,比如 linear_model.LogisticRegression()中有参数C.

sklearn中的GrideSearchCV可方便调参过程.如下:

import numpy as np
from sklearn import linear_model
from skearn.grid_search import GridSearchCV # read my data
X_train, X_test, y_train, y_test=load_data(file='total_data.csv', X_start=2, X_end=37, y_position=64, classification=False) # 参数 C 的搜索空间
Cs = np.logspace(-1, 1, num = 100) model = linear_model.LogisticRegression()
grid = GridSearchCV(estimator=model, param_grid=dict(C=Cs))
grid.fit(X_train, y_train) print grid
print grid.best_score_
print grid.best_estimator_

输出:

GridSearchCV(cv=None, error_score='raise',
estimator=LogisticRegression(C=1.0, class_weight=None, dual=False, fit_intercept=True,
intercept_scaling=1, max_iter=100, multi_class='ovr', n_jobs=1,
penalty='l2', random_state=None, solver='liblinear', tol=0.0001,
verbose=0, warm_start=False),
fit_params={}, iid=True, n_jobs=1,
param_grid={'C': array([ 0.1 , 0.10476, ..., 9.54548, 10. ])},
pre_dispatch='2*n_jobs', refit=True, scoring=None, verbose=0)
0.694444444444
LogisticRegression(C=0.23101297000831597, class_weight=None, dual=False,
fit_intercept=True, intercept_scaling=1, max_iter=100,
multi_class='ovr', n_jobs=1, penalty='l2', random_state=None,
solver='liblinear', tol=0.0001, verbose=0, warm_start=False)

要注意grid = GridSearchCV(estimator=model, param_grid=dict(C=Cs))的C, C必须是LogisticRegression的一个参数名字,否则报错.

GrideSearchCV 优化算法参数的更多相关文章

  1. DeepLearning.ai学习笔记(二)改善深层神经网络:超参数调试、正则化以及优化--Week2优化算法

    1. Mini-batch梯度下降法 介绍 假设我们的数据量非常多,达到了500万以上,那么此时如果按照传统的梯度下降算法,那么训练模型所花费的时间将非常巨大,所以我们对数据做如下处理: 如图所示,我 ...

  2. 机器学习超参数优化算法-Hyperband

    参考文献:Hyperband: Bandit-Based Configuration Evaluation for Hyperparameter Optimization I. 传统优化算法 机器学习 ...

  3. 梯度优化算法总结以及solver及train.prototxt中相关参数解释

    参考链接:http://sebastianruder.com/optimizing-gradient-descent/ 如果熟悉英文的话,强烈推荐阅读原文,毕竟翻译过程中因为个人理解有限,可能会有谬误 ...

  4. Andrew Ng - 深度学习工程师 - Part 2. 改善深层神经网络:超参数调试、正则化以及优化(Week 2. 优化算法)

    ===========第2周 优化算法================ ===2.1 Mini-batch 梯度下降=== epoch: 完整地遍历了一遍整个训练集 ===2.2 理解Mini-bat ...

  5. [Algorithm] 群体智能优化算法之粒子群优化算法

    同进化算法(见博客<[Evolutionary Algorithm] 进化算法简介>,进化算法是受生物进化机制启发而产生的一系列算法)和人工神经网络算法(Neural Networks,简 ...

  6. MOPSO 多目标例子群优化算法

    近年来,基于启发式的多目标优化技术得到了很大的发展,研究表明该技术比经典方法更实用和高效.有代表性的多目标优化算法主要有NSGA.NSGA-II.SPEA.SPEA2.PAES和PESA等.粒子群优化 ...

  7. SMO优化算法(Sequential minimal optimization)

    原文:http://www.cnblogs.com/jerrylead/archive/2011/03/18/1988419.html SMO算法由Microsoft Research的John C. ...

  8. 优化算法-BFGS

    优化算法-BFGS BGFS是一种准牛顿算法, 所谓的"准"是指牛顿算法会使用Hessian矩阵来进行优化, 但是直接计算Hessian矩阵比较麻烦, 所以很多算法会使用近似的He ...

  9. deeplearning.ai 改善深层神经网络 week2 优化算法 听课笔记

    这一周的主题是优化算法. 1.  Mini-batch: 上一门课讨论的向量化的目的是去掉for循环加速优化计算,X = [x(1) x(2) x(3) ... x(m)],X的每一个列向量x(i)是 ...

随机推荐

  1. 新概念英语(1-111)The most expensive model

    Lesson 111 The most expensive model 最昂贵的型号 Listen to the tape then answer this question. Can Mr. Fri ...

  2. hadoop2.6.0实践:A02 问题处理 util.NativeCodeLoader: Unable to load native-hadoop library for your platform

    ############################################################# hadoop "util.NativeCodeLoader: Un ...

  3. netty学习--handler传递

    在netty中的处理链pipeline中,事件是按顺序传递的,把自己拟人为netty程序,针对进来(inbound)的请求,会从head开始,依次往tail传递. pipeline采用了链表结构,he ...

  4. 复习HTML+CSS(5)

    n  <meta>标记 <meta>的主要作用,是提供网页的源信息.比如:指定网页的搜索关键字 <meta>标记有两个属性:http-equiv和name. 1. ...

  5. IDLE常用快捷键汇总(转)

    IDLE(An Integrated DeveLopment Environment for Python)是Python自带的编译器,在初学者,或写小程序,或用于验证的时候,经常用到!如果能熟练掌握 ...

  6. No Java compiler available

    <!-- 添加tomcat支持 --> <dependency> <groupId>org.springframework.boot</groupId> ...

  7. 学习React系列(七)——Fragments、Portals、Error Boundaries与WEB组件

    React.Fragment portals Error Boundaries WEB组件 React.Fragment 想象一个场景,想把td包装为组件添加到table中去,代码如下: class ...

  8. 开源协议瞎扯淡,什么是 MIT 协议?[转]

    图片来源:http://ruby-china.org/topics/15979

  9. [LeetCode] Coin Change 2 硬币找零之二

    You are given coins of different denominations and a total amount of money. Write a function to comp ...

  10. [LeetCode] Base 7 基数七

    Given an integer, return its base 7 string representation. Example 1: Input: 100 Output: "202&q ...