1. print "Performing greedy feature selection..."
  2. score_hist = []
  3. N = 10
  4. good_features = set([])
  5. # Greedy feature selection loop
  6. while len(score_hist) < 2 or score_hist[-1][0] > score_hist[-2][0]:
  7. scores = []
  8. for f in range(len(Xts)):
  9. if f not in good_features:
  10. feats = list(good_features) + [f]
  11. Xt = sparse.hstack([Xts[j] for j in feats]).tocsr()
  12. score = cv_loop(Xt, y, model, N)
  13. scores.append((score, f))
  14. print "Feature: %i Mean AUC: %f" % (f, score)
  15. good_features.add(sorted(scores)[-1][1])
  16. score_hist.append(sorted(scores)[-1])
  17. print "Current features: %s" % sorted(list(good_features))

注意还没结束:

  1. # Remove last added feature from good_features
  2. good_features.remove(score_hist[-1][1])

from kaggle

machine learning in coding(python):使用贪心搜索【进行特征选择】的更多相关文章

  1. 机器学习系统设计(Building Machine Learning Systems with Python)- Willi Richert Luis Pedro Coelho

    机器学习系统设计(Building Machine Learning Systems with Python)- Willi Richert Luis Pedro Coelho 总述 本书是 2014 ...

  2. Python (1) - 7 Steps to Mastering Machine Learning With Python

    Step 1: Basic Python Skills install Anacondaincluding numpy, scikit-learn, and matplotlib Step 2: Fo ...

  3. Python -- machine learning, neural network -- PyBrain 机器学习 神经网络

    I am using pybrain on my Linuxmint 13 x86_64 PC. As what it is described: PyBrain is a modular Machi ...

  4. Getting started with machine learning in Python

    Getting started with machine learning in Python Machine learning is a field that uses algorithms to ...

  5. 【机器学习Machine Learning】资料大全

    昨天总结了深度学习的资料,今天把机器学习的资料也总结一下(友情提示:有些网站需要"科学上网"^_^) 推荐几本好书: 1.Pattern Recognition and Machi ...

  6. How do I learn machine learning?

    https://www.quora.com/How-do-I-learn-machine-learning-1?redirected_qid=6578644   How Can I Learn X? ...

  7. 【Machine Learning】决策树案例:基于python的商品购买能力预测系统

    决策树在商品购买能力预测案例中的算法实现 作者:白宁超 2016年12月24日22:05:42 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现的深入理解.本 ...

  8. 【Machine Learning】Python开发工具:Anaconda+Sublime

    Python开发工具:Anaconda+Sublime 作者:白宁超 2016年12月23日21:24:51 摘要:随着机器学习和深度学习的热潮,各种图书层出不穷.然而多数是基础理论知识介绍,缺乏实现 ...

  9. [Python & Machine Learning] 学习笔记之scikit-learn机器学习库

    1. scikit-learn介绍 scikit-learn是Python的一个开源机器学习模块,它建立在NumPy,SciPy和matplotlib模块之上.值得一提的是,scikit-learn最 ...

随机推荐

  1. JdbcTemplate:Jdbc模板和数据库元数据

    通过 Jdbc .C3P0 .Druid 的使用我们会发现即使我们做了工具的封装,但重复性的代码依旧很多.我们可以通过 JdbcTemplate 即 Jdbc 模板来使我们的代码更加简洁,逻辑更加清晰 ...

  2. lua_string_pattern

    两大特点: 1. string库中所有的字符索引从前往后是1,2,...;从后往前是-1,-2,... 2. string库中所有的function都不会直接操作字符串,而是返回一个新的字符串. 库函 ...

  3. 如何修改wampserver中mysql中字符编码的解决方案

    因为我用的一般都是utf8,所以有必要改一下: 打开mysql控制台,输入密码登录之后,执行命令: show variables like ‘%char%’; 注意引号的中英文格式以及最后面的分号不要 ...

  4. PHP中单例模式与工厂模式

    单例模式概念 单例模式是指整个应用中类只有一个对象实例的设计模式. 单例模式的特点 一个类在整个应用中只有一个实例 类必须自行创建这个实例 必须自行向整个系统提供这个实例 php中使用单例模式的原因 ...

  5. Hibernate 延迟加载剖析与代理模式应用

    本文来源于:http://www.ibm.com/developerworks/cn/java/j-lo-hibernatelazy/#icomments

  6. HDU_5723_最小生成树+任意两点距离的期望

    Abandoned country Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  7. Python 之lxml解析库

    一.XPath常用规则 二.解析html文件 from lxml import etree # 读取HTML文件进行解析 def parse_html_file(): html = etree.par ...

  8. PHP 之ftp客户端类封装实现

    <?php /** * Class FtpClient */ class FtpClient { private $host = '';//远程服务器地址 private $user = ''; ...

  9. Redis事物及锁的运用

    redis与mysql事物比较如下: 下面是一个redis事物运用于买票的demo

  10. 本地读取服务器Xml文件及本地读本地的xml

    updateUrl="ServerUrl"(服务器路径) WebClient wc = new WebClient(); Stream stream = wc.OpenRead(u ...