当前位置:网站首页>对pandas 数据进行数据打乱并选取训练机与测试机集
对pandas 数据进行数据打乱并选取训练机与测试机集
2020-11-06 01:27:00 【IT界的小小小学生】
描述
在机器学习中,拿到一堆训练数据一般会需要将数据切分成训练集和测试集,或者切分成训练集、交叉验证集和测试集,为了避免切分之后的数据集在特征分布上出现偏倚,我们需要先将数据打乱,使数据随机排序,然后在进行切分。
需要用的方法如下:
注:df代表一个pd.DataFrame
df = df.sample(frac=1.0): 按100%的比例抽样即达到打乱数据的效果
df = df.reset_index():打乱数据之后index也是乱的,如果你的index没有特征意义的话,直接重置就可以了,否则就在打乱之前把index加进新的一列,再生成无意义的index
train = df.loc[0:a]: 进行切分操作,切分比例看情况定
cv = df.loc[a+1:b]:
test = df.loc[b+1:-1]:
版权声明
本文为[IT界的小小小学生]所创,转载请带上原文链接,感谢
https://vip01.blog.csdn.net/article/details/93796160
边栏推荐
- Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
- 自然语言处理之命名实体识别-tanfordcorenlp-NER(一)
- Python自动化测试学习哪些知识?
- Real time data synchronization scheme based on Flink SQL CDC
- Analysis of ThreadLocal principle
- [performance optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
- Calculation script for time series data
- C language 100 question set 004 - statistics of the number of people of all ages
- Don't go! Here is a note: picture and text to explain AQS, let's have a look at the source code of AQS (long text)
- 车的换道检测
猜你喜欢

Existence judgment in structured data

Pattern matching: The gestalt approach一种序列的文本相似度方法

条码生成软件如何隐藏部分条码文字

Can't be asked again! Reentrantlock source code, drawing a look together!

大数据应用的重要性体现在方方面面

2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...

How do the general bottom buried points do?

读取、创建和运行多个文件的3个Python技巧

How to select the evaluation index of classification model

直播预告 | 微服务架构学习系列直播第三期
随机推荐
车的换道检测
Computer TCP / IP interview 10 even asked, how many can you withstand?
网络安全工程师演示:原来***是这样获取你的计算机管理员权限的!【维持】
ipfs正舵者Filecoin落地正当时 FIL币价格破千来了
嘘!异步事件这样用真的好么?
Grouping operation aligned with specified datum
如何将数据变成资产?吸引数据科学家
如果前端不使用SPA又能怎样?- Hacker News
神经网络简史
向北京集结!OpenI/O 2020启智开发者大会进入倒计时
Calculation script for time series data
Want to do read-write separation, give you some small experience
hadoop 命令总结
加速「全民直播」洪流,如何攻克延时、卡顿、高并发难题?
GBDT与xgb区别,以及梯度下降法和牛顿法的数学推导
Examples of unconventional aggregation
DevOps是什么
如何对Pandas DataFrame进行自定义排序
熬夜总结了报表自动化、数据可视化和挖掘的要点,和你想的不一样
Listening to silent words: hand in hand teaching you sign language recognition with modelarts