python RandomForest跑feature重要性
其实呢,就是直接调用一个函数的事情。。。
#coding=utf-8
from sklearn.tree import DecisionTreeClassifier
from matplotlib.pyplot import *
from sklearn.cross_validation import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.externals.joblib import Parallel, delayed
from sklearn.tree import export_graphviz
final = open('full_train.csv','r')
print "open good!"
data = [line.strip().split(',') for line in final]
feature = [[float(x) for x in row[1:]] for row in data]
target = [int(row[0]) for row in data]
print "del good!"
#拆分训练集和测试集
feature_train, feature_test, target_train, target_test = train_test_split(feature, target, test_size=0.1, random_state=42)
#分类型决策树
clf = RandomForestClassifier(n_estimators = 8)
print "train good"
#训练模型
s = clf.fit(feature_train , target_train)
print s
print "fuck high"
#评估模型准确率
r = clf.score(feature_test , target_test)
print r
print '判定结果:%s' % clf.predict(feature_test[0])
#print clf.predict_proba(feature_test[0])
print '所有的树:%s' % clf.estimators_
print clf.classes_
print clf.n_classes_
print '各feature的重要性:%s' % clf.feature_importances_
print clf.n_outputs_
python RandomForest跑feature重要性的更多相关文章
- python书写日志的重要性?
转自:https://blog.csdn.net/weixin_43063753/article/details/82899395 程序为什么要写日志?#为了能够在程序在运行过程中记录错误,方便维护, ...
- python应用-跑马灯
import os import time def main(): str1='欢迎来到前锋学习Python' while True: os.system('cls') print(str1) tim ...
- 说说这篇「我为什么从python转向go
作者 CMGS2015.05.17 15:47* 写了7891字,被143人关注,获得了97个喜欢 说说这篇「我为什么从python转向go」 字数3748 阅读24227 评论21 喜欢81 恩看了 ...
- python教程与资料
网上有个人写的python快速教程,非常好.比看书好多了.猛击下面的链接地址 http://www.douban.com/group/topic/30008503/ python文档资料收集 pyth ...
- 离线安装 Python 2.7, paramiko 和 tornado
无非就是离线安装, 步骤比较繁琐, 记录一下. 需求很简单, 一个离线安装的 Python, 能跑 tornado 和 paramiko 1. 离线安装 Python 2.7 .tgz cd Pyth ...
- 【Python大系】Python快速教程
感谢原作者:Vamei 出处:http://www.cnblogs.com/vamei 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题. Python包含的内容很多,加上各种标准库.拓展库, ...
- C4.5,CART,randomforest的实践
#################################Weka-J48(C4.5)################################# ################### ...
- Python快速教程目录(转)
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题. Python包含的内容 ...
- Python快速教程
作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 怎么能快速地掌握Python?这是和朋友闲聊时谈起的问题. Python包含的内容 ...
随机推荐
- VC++常用数据类型及其操作详解
原文地址:http://blog.csdn.net/ithomer/article/details/5019367 VC++常用数据类型及其操作详解 一.VC常用数据类型列表 二.常用数据类型转化 2 ...
- dns轮询
负载均衡最开始一步,利用它实现负载均衡集群的定位
- shell脚本中冒号
格式:: your comment here 格式:# your comment here 写代码注释(单行注释). 例如: 格式:: 'comment line1 comment line2 mor ...
- 虚拟机Ubuntu 18.04安装RabbitMQ 3.7.9
Windows 10家庭中文版,VirtualBox,Ubuntu 18.04,Rabbitmq 3.7.9,Erlang/OTP 20 [erts-9.2], 在虚拟机上装好了Ubuntu,写了一个 ...
- [转]安装ambari
一.准备工作: 基本工具 yumrpmscpcurlwgetpdsh前几个一般系统都自带了,pdsh需要自己装 yum install pdsh 2.配置hosts vim /etc/hosts 10 ...
- hdu2888 二维ST表(RMQ)
二维RMQ其实和一维差不太多,但是dp时要用四维 /* 二维rmq */ #include<iostream> #include<cstring> #include<cs ...
- pytest十五:pytest-html 生成 html 报告
pytest-HTML 是一个插件,pytest 用于生成测试结果的 HTML 报告.兼容 Python 2.7,3.6 pytest-html1.github 上源码地址[https://githu ...
- python 全栈开发,Day43(python全栈11期月考题)
python全栈11期月考题 1.常用字符串格式化有哪些?并说明他们的区别 2.请手写一个单例模式(面试题) 3.利用 python 打印前一天的本地时间,格式为‘2018-01-30’(面试题) 4 ...
- 步步为营-66-Socket通信
1.0 版本 1.1 服务器端 using System; using System.Collections.Generic; using System.Linq; using System.Net; ...
- 《转》利用cxf实现webservice
首先下载cxf包,目前最新的版本是apache-cxf-2.1.,下栽地址http://cxf.apache.org/download.html. 1. 首先新建一个web工程CxfService,倒 ...