当前位置:网站首页>对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
边栏推荐
- Didi elasticsearch cluster cross version upgrade and platform reconfiguration
- Cos start source code and creator
- 【新閣教育】窮學上位機系列——搭建STEP7模擬環境
- In depth understanding of the construction of Intelligent Recommendation System
- Asp.Net Core learning notes: Introduction
- Sort the array in ascending order according to the frequency
- 快快使用ModelArts,零基礎小白也能玩轉AI!
- 简直骚操作,ThreadLocal还能当缓存用
- Working principle of gradient descent algorithm in machine learning
- Calculation script for time series data
猜你喜欢
随机推荐
GDB除錯基礎使用方法
How to select the evaluation index of classification model
用Python构建和可视化决策树
《Google軟體測試之道》 第一章google軟體測試介紹
Flink on paasta: yelp's new stream processing platform running on kubernetes
10 easy to use automated testing tools
Grouping operation aligned with specified datum
mac 下常用快捷键,mac启动ftp
X Window System介紹
[performance optimization] Nani? Memory overflow again?! It's time to sum up the wave!!
Kitty中的动态线程池支持Nacos,Apollo多配置中心了
Use of vuepress
事半功倍:在没有机柜的情况下实现自动化
免费的专利下载教程(知网、espacenet强强联合)
Calculation script for time series data
简直骚操作,ThreadLocal还能当缓存用
幽默:黑客式编程其实类似机器学习!
【新閣教育】窮學上位機系列——搭建STEP7模擬環境
数字城市响应相关国家政策大力发展数字孪生平台的建设
03_ Detailed explanation and test of installation and configuration of Ubuntu Samba