我的代码- rf sampling
# coding: utf-8
# In[6]:
import pandas as pd
import numpy as np
from sklearn import tree
from sklearn.svm import SVC
from sklearn.grid_search import GridSearchCV
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report, confusion_matrix
from sklearn.preprocessing import binarize
from sklearn.preprocessing import LabelEncoder
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import Normalizer
from sklearn.metrics import f1_score
from sklearn.metrics import accuracy_score,recall_score,average_precision_score,auc
from imblearn.over_sampling import SMOTE
# In[7]:
data= pd.read_csv(r"D:\Users\sgg91044\Desktop\Copy of sampling.csv")
# In[8]:
data.iloc[:,5:22] = data.iloc[:,5:22].apply(pd.to_numeric,errors='coerce')
# In[9]:
data.head()
# In[10]:
data.Target = data.Target.astype("category")
# In[11]:
Y = data.Target
X = data.drop(columns='Target')
# In[13]:
X=X.drop(columns=['Recipe_Name','defect_count'])
# In[14]:
X.head()
# In[64]:
X=X.drop(columns=['defect_count'])
X.head()
# In[8]:
for i in range(0,18):
med = np.median(X.iloc[:,i][X.iloc[:,i].isna() == False])
X.iloc[:,i] = X.iloc[:,i].fillna(med)
# In[9]:
nz = Normalizer()
X.iloc[:,10:12]=pd.DataFrame(nz.fit_transform(X.iloc[:,10:12]),columns=X.iloc[:,10:12].columns)
X.iloc[:,0:3]=pd.DataFrame(nz.fit_transform(X.iloc[:,0:3]),columns=X.iloc[:,0:3].columns)
X
# In[15]:
X_train, X_test, y_train, y_test = train_test_split(
X, Y, test_size=0.2, random_state=0)
# In[16]:
sm = SMOTE(random_state=12, ratio = 1.0)
x_train_smote, y_train_smote = sm.fit_sample(X_train, y_train)
# In[17]:
print(y_train.value_counts(), np.bincount(y_train_smote))
# In[18]:
from sklearn.ensemble import RandomForestClassifier
# Make the random forest classifier
random_forest = RandomForestClassifier(n_estimators = 100, random_state = 50, verbose = 1, oob_score = True, n_jobs = -1)
# In[19]:
# Train on the training data
random_forest.fit(x_train_smote,y_train_smote)
# In[20]:
rm_trans=random_forest.transform()
# In[21]:
# Make predictions on the test data
y_pred = random_forest.predict(X_test)
# In[22]:
print(classification_report(y_pred=y_pred,y_true=y_test))
# In[23]:
print(confusion_matrix(y_pred=y_pred,y_true=y_test))
# In[24]:
f1_score(y_pred=y_pred,y_true=y_test)
# In[25]:
print("Accuracy of Random_forest:",round(accuracy_score(y_pred=y_pred,y_true=y_test) * 100,2),"%")
# In[26]:
print("Sensitivity of Random_forest:",round(recall_score(y_pred=y_pred,y_true=y_test)*100,2),"%")
我的代码- rf sampling的更多相关文章
- LoRa术语
ADR Adaptive Data Rate 自适应数据率 AES Advanced Encryption Standard 高级加密标准 AFA ...
- 智能灯控(基于ZigBee)
时间:2017年12月 阶段:大二上学期 背景:单片机原理与应用课设 名称:智能灯控 摘要 本系统实现了多方式控灯功能,有按键控灯.串口指令控灯.点对点无线射频控灯.AI模式控灯.其中AI模式控灯是通 ...
- RF 测试代码体会
这里的需求是完成一个cc2540 RF测试程序.实现功能为开发板按键控制 RF 发射频率的改变. 首先被告知要用PTM来做这个测试程序,然后我去了PTM的介绍文档,地址为 http://process ...
- SMOTE RF MLP demo use cross_val_score to find best argument 处理不平衡数据的demo代码 先做smote处理 再用交叉验证找到最好的模型参数 实践表明MLP更好
# _*_coding:UTF-8_*_ from sklearn.externals.six import StringIO from sklearn import tree import pydo ...
- 图像抠图算法学习 - Shared Sampling for Real-Time Alpha Matting
一.序言 陆陆续续的如果累计起来,我估计至少有二十来位左右的朋友加我QQ,向我咨询有关抠图方面的算法,可惜的是,我对这方面之前一直是没有研究过的.除了利用和Photoshop中的魔棒一样的技术或者 ...
- 决策树(中)-集成学习、RF、AdaBoost、Boost Tree、GBDT
参考资料(要是对于本文的理解不够透彻,必须将以下博客认知阅读): 1. https://zhuanlan.zhihu.com/p/86263786 2.https://blog.csdn.net/li ...
- MATLAB的PLOT函数线型设置及横坐标为字符串的代码实例
2.横坐标为字符串的代码实例 cell={‘PLS’,’SVM’,’RF’,’NNET’,’NB’,’PLR’,’C5.0′,’PDA’,’KNN’,’GLM’,’BCT’};%分类方法yData=[ ...
- 某互联网后台自动化组合测试框架RF+Sikuli+Python脚本
某互联网后台自动化组合测试框架RF+Sikuli+Python脚本 http://www.jianshu.com/p/b3e204c8651a 字数949 阅读323 评论1 喜欢0 一.**Robo ...
- 【iOS 使用github上传代码】详解
[iOS 使用github上传代码]详解 一.github创建新工程 二.直接添加文件 三.通过https 和 SSH 操作两种方式上传工程 3.1https 和 SSH 的区别: 3.1.1.前者可 ...
随机推荐
- linux安装命令出错(could not resolve host mirrorlist.centos.org)
本次问题出现在虚拟机安装的centos7系统之后,使用yum命令安装wget命令(yum -y install wget),出现could not resolve host mirrorlist.ce ...
- 使用该方法在ubuntu下安装flashplayer的rpm包
Ubuntu的软件包格式是deb,如果要安装rpm的包,则要先用alien把rpm转换成deb. sudo apt-get install alien #alien默认没有安装,所以首先要安装它 su ...
- ABP-DDD学习
有一个比较大的项目,打算使用 DDD +ABP +微服务 开发: 1.涉及到社交: 业务场景比较复杂:会多变: 2.采用前后端分离,netcore+vue; 3.部署采用K8S +docker 进行部 ...
- JavaScript js 引入CDN 不生效 注意事项
[博客园cnblogs笔者m-yb原创,转载请加本文博客链接,笔者github: https://github.com/mayangbo666,公众号aandb7,QQ群927113708]https ...
- ng-repeat 中的track by
<div style="font-size:15px"ng-repeat="item in groups.items track by $index"&g ...
- Python字符串与格式化的一点用法
#python的基本语法网上已经有很多详细的解释了,写在这里方便自己记忆一些 1.python于C语言不同的是,python没有字符的概念,所谓的字符就是长度为1的字符串,使用切片或者索引同样可以对字 ...
- python基础(字符串常用方法)
字符串不常用方法: 字符串常用的方法: #看源代码 按住ctrl点击方法名 用户注册的小程序 import datetimeusers = []passwds = []for i in range(3 ...
- ARM内核单片机Bootloader中断向量重定位问题
Bootloader中断向量重定位问题 1.Bootloader程序在内核Cortex-M0+内核中运行时需要进行地址跳转执行应用程序主程序,此时就涉及到了中断向量重定位问题,以下截图为单片机启动文件 ...
- springboot整合mybatics PLUS
首先添加maven依赖: <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactI ...
- task打印执行结果
使用debug输出task执行的register: - name: check extract session # script: /app/ansiblecfg/XXX/roles/test/tas ...