当前位置: 首页 > news >正文

kaggle学习 eloData项目(1)-数据校验

文章目录

  • kaggle学习 eloData项目(1)-数据校验
    • (1) 数据基本情况查看
    • (2) 数据校验
    • (3) 数据探究
  • 小结

kaggle学习 eloData项目(1)-数据校验

  不能懈怠,加油,eloData项目在B站有讲解课,趁着热乎赶紧学一下。文章参考:kaggle比赛案例:Elo Merchant Category Recommendation(1)

  • 库文件
import os
import numpy as np
import pandas as pd
import gc       # 主动管理内存,清理内存需要
import seaborn as sns
import matplotlib.pyplot as plt

(1) 数据基本情况查看

  • 1.1 读取表格数据
    df = pd.read_excel('./eloData/Data_Dictionary.xlsx',header=2,sheet_name='train')print(df)
  • 1.2 读取表格数据的前五个查看
    df = pd.read_csv('./eloData/sample_submission.csv',header=0).head(5)print(df)
  • 1.3 读取数据的基本信息
    df = pd.read_csv('./eloData/sample_submission.csv', header=0).info()print(df)
  • 1.4 读取训练集与测试集数据
    train = pd.read_csv('./eloData/train.csv')test = pd.read_csv('./eloData/test.csv')print(train.shape,test.shape)

(2) 数据校验

  • 2.1 训练集 id 是否有重复
    if train['card_id'].nunique() == train.shape[0]:print("2.1.1True")# 测试集 id 是否有重复if test['card_id'].nunique() == test.shape[0]:print("2.1.2True")# 检验 训练集与测试集的id 是否唯一if ((train['card_id'].nunique()+test['card_id'].nunique())== len(set(train['card_id'].values.tolist()+test['card_id'].values.tolist())))  :print("2.1.3True")
  • 2.2 检验数据确实情况
    # 按列缺失值汇总查询# 训练集print(train.isnull().sum())# 测试集 缺失一条print(test.isnull().sum())
  • 2.3 异常值检测
    # 查看标签列是否有异常statistics = train['target'].describe();print("statistics",statistics)sns.set()sns.histplot(train['target'],kde=True)# plt.show()# 找出异常值 查看print("异常值个数:",(train['target']<-30).sum())# 异常值占比确认 一般采用 3δ 原则print("异常值范围:",statistics.loc['mean']-3*statistics.loc['std'])
  • 补充:聊聊python dropna()和notnull()的用法区别
  • 当未精确定位到某一列,但该列中存在空值时,dropna()会将空值所在行删除,而notnull()不会删除;在精确定位到某一列后,dropna()会输出series,而notnull()输出DataFrame。

(3) 数据探究

  • 3.1 单因素分析
    np.sort(train['first_active_month'].unique())print(len(np.sort(train['first_active_month'].unique())))# pandas的notnull函数,用于返回非空值的集合。np.sort(test[test.notnull()['first_active_month']]['first_active_month'].unique())print(len(np.sort(test[test.notnull()['first_active_month']]['first_active_month'].unique())))# 绘图查看异常值(train['feature_1'].value_counts().sort_index()/train.shape[0]).plot()(test['feature_1'].value_counts().sort_index()/train.shape[0]).plot()plt.legend(['train','test'])plt.xlabel('feature_1')plt.ylabel('ratio')plt.show()
  • 3.2 多因素联合分布
    features = train.columnsfeatures_ = features.drop(['card_id','target'])n = len(features_)for i in range(n-1):for j in range(i+1,n):f1 = features_[i]f2 = features_[j]train_com = train[[f1,f2]]test_com = test[[f1,f2]]com1 = train_com[f1].values.astype(str).tolist()com2 = train_com[f2].values.astype(str).tolist()com1_ = test_com[f1].values.astype(str).tolist()com2_ = test_com[f2].values.astype(str).tolist()data1 = pd.Series([com1[i]+'&'+com2[i] for i in range(train.shape[0])]).value_counts().sort_index()/train.shape[0]data2 = pd.Series([com1_[i] + '&' + com2_[i] for i in range(test.shape[0])]).value_counts().sort_index()/test.shape[0]data1.plot()data2.plot()plt.legend(['train', 'test'])plt.xlabel('&'.join([f1,f2]))plt.ylabel('ratio')plt.show()
  • 放一张图展示一下;
    在这里插入图片描述

小结

  海到无边天作岸,山登绝顶我为峰。
  总之,加油,共勉吧!

http://www.lryc.cn/news/480388.html

相关文章:

  • ORACLE RAC用DNS服务器的配置
  • vue3 + vite 实现版本更新检查(检测到版本更新时提醒用户刷新页面)
  • 【CSP】爆零的独特姿势
  • Git仓库
  • 【科研日常】论文投稿的几大状态
  • SSLHandshakeException错误解决方案
  • python数据结构基础(7)
  • 【系统集成项目管理工程师】英语词汇对照表-项目管理类
  • 购物车-多元素组合动画css
  • 【计网不挂科】计算机网络期末考试——【选择题&填空题&判断题&简述题】题库(3)
  • [ vulnhub靶机通关篇 ] 渗透测试综合靶场 DarkHole:1 通关详解 (附靶机搭建教程)
  • 【LeetCode】移除链表中等于设定值的元素、反转链表
  • Redis - 主从复制
  • UE5 HLSL 学习笔记
  • 一个简单ASP.NET购物车设计
  • 双向循环列表
  • go项目出现了ambiguous import要怎么解决?
  • 更改Ubuntu22.04锁屏壁纸
  • ROS2humble版本使用colcon构建包
  • CSRF 跨站请求伪造的实现原理和预防措施
  • 【LeetCode】【算法】22. 括号生成
  • WPF+MVVM案例实战与特效(二十五)- 3D粒子波浪效果实现
  • wsl2安装和使用
  • 【划分型 DP-最优划分】【腾讯笔试压轴】【hard】力扣132. 分割回文串 II
  • Kubernetes-镜像加速篇-01-加速工具
  • 字母的异位数
  • 达梦数据库DM Exception字符串截断错误,略坑~
  • vue实现图片无限滚动播放
  • python爬虫指南——初学者避坑篇
  • Vivado+Vscode联合打造verilog环境