河北高校邀请赛——二手车交易价格预测-Task2 数据分析

EDA-数据探索性分析

赛题:零基础入门数据挖掘 - 二手车交易价格预测
要求参赛选手根据给定的数据集,建立模型,预测二手汽车的交易价格。

一、EDA目标

  1. EDA的价值主要在于熟悉数据集,了解数据集,对数据集进行验证来确定所获得数据集可以用于接下来的机器学习或者深度学习使用。
  2. 了解变量间的相互关系以及变量与预测值之间的存在关系。
  3. 引导数据科学从业者进行数据处理以及特征工程的步骤,使数据集的结构和特征集让接下来的预测问题更加可靠。

二、内容介绍

  1. 载入各种数据科学以及可视化库
    数据科学库 pandas、numpy、scipy;
    可视化库 matplotlib、seabon;
    其他;
  2. 载入数据
    载入训练集和测试集;
    简略观察数据(head()+shape);
  3. 数据总览
    通过describe()来熟悉数据的相关统计量;
    通过info()来熟悉数据类型;
  4. 判断数据缺失和异常
    查看每列的存在nan情况;
    异常值检测;
  5. 了解预测值的分布
    总体分布概况(无界约翰逊分布等);
    查看skewness 和 kurtosis;
    查看预测值的具体频数;
  6. 特征分为类别特征和数字特征,并对类别特征查看unique分布
  7. 数字特征分析
    相关性分析;
    查看几个特征得 偏度和峰值;
    每个数字特征得分布可视化;
    数字特征相互之间的关系可视化;
    多变量互相回归关系可视化;
  8. 类型特征分析
    unique分布;
    类别特征箱形图可视化;
    类别特征的小提琴图可视化;
    类别特征的柱形图可视化类别;
    特征的每个类别频数可视化(count_plot);
  9. 用pandas_profiling生成数据报告

三、代码示例

1.载入各种数据科学以及可视化库

#coding:utf-8
#导入warnings包,利用过滤器来实现忽略警告语句。
import warnings
warnings.filterwarnings('ignore')

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import missingno as msno

2.载入数据

1) 载入训练集和测试集
## 1) 载入训练集和测试集;
Train_data = pd.read_csv('./data/car_train_0110.csv', sep=' ')
Test_data = pd.read_csv('./data/car_testA_0110.csv', sep=' ')

所有特征集均脱敏处理

  1. name - 汽车编码
  2. regDate - 汽车注册时间
  3. model - 车型编码
  4. brand - 品牌
  5. bodyType - 车身类型
  6. fuelType - 燃油类型
  7. gearbox - 变速箱
  8. power - 汽车功率
  9. kilometer - 汽车行驶公里
  10. notRepairedDamage - 汽车有尚未修复的损坏
  11. regionCode - 看车地区编码
  12. seller - 销售方
  13. offerType - 报价类型
  14. creatDate - 广告发布时间
  15. price - 汽车价格
  16. 包含v0-23在内24个匿名特征(根据汽车的评论、标签等大量信息得到的embedding向量)【人工构造 匿名特征】
2) 简略观察数据(head()+shape)
## 2) 简略观察数据(head()+shape)
Train_data.head().append(Train_data.tail())
Train_data.shape
(250000, 40)
Test_data.head().append(Test_data.tail())
Test_data.shape
(50000, 39)

在接下来的操作中,养成看数据集的head()及shape的习惯,如果对自己的pandas等操作不放心,建议执行一步看一下。

3.总览数据概况

  1. describe中有每列的统计量(个数count、平均值mean、方差std、最小值min、中位数25% 50% 75% 、最大值),可迅速掌握数据的大概的范围,有助于异常值的判断,比如999 9999、-1 等值可能是nan的另外一种表达方式,需要注意。
  2. 通过info来了解数据每列的type,有助于了解是否存在除了nan以外的特殊符号异常
1) 通过describe()来熟悉数据的相关统计量
## 1) 通过describe()来熟悉数据的相关统计量
Train_data.describe()
Test_data.describe()
2) 通过info()来熟悉数据类型
## 2) 通过info()来熟悉数据类型
Train_data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 250000 entries, 0 to 249999
Data columns (total 40 columns):
 #   Column             Non-Null Count   Dtype  
---  ------             --------------   -----  
 0   SaleID             250000 non-null  int64  
 1   name               250000 non-null  int64  
 2   regDate            250000 non-null  int64  
 3   model              250000 non-null  float64
 4   brand              250000 non-null  int64  
 5   bodyType           224620 non-null  float64
 6   fuelType           227510 non-null  float64
 7   gearbox            236487 non-null  float64
 8   power              250000 non-null  int64  
 9   kilometer          250000 non-null  float64
 10  notRepairedDamage  201464 non-null  float64
 11  regionCode         250000 non-null  int64  
 12  seller             250000 non-null  int64  
 13  offerType          250000 non-null  int64  
 14  creatDate          250000 non-null  int64  
 15  price              250000 non-null  int64  
 16  v_0                250000 non-null  float64
 17  v_1                250000 non-null  float64
 18  v_2                250000 non-null  float64
 19  v_3                250000 non-null  float64
 20  v_4                250000 non-null  float64
 21  v_5                250000 non-null  float64
 22  v_6                250000 non-null  float64
 23  v_7                250000 non-null  float64
 24  v_8                250000 non-null  float64
 25  v_9                250000 non-null  float64
 26  v_10               250000 non-null  float64
 27  v_11               250000 non-null  float64
 28  v_12               250000 non-null  float64
 29  v_13               250000 non-null  float64
 30  v_14               250000 non-null  float64
 31  v_15               250000 non-null  float64
 32  v_16               250000 non-null  float64
 33  v_17               250000 non-null  float64
 34  v_18               250000 non-null  float64
 35  v_19               250000 non-null  float64
 36  v_20               250000 non-null  float64
 37  v_21               250000 non-null  float64
 38  v_22               250000 non-null  float64
 39  v_23               250000 non-null  float64
dtypes: float64(30), int64(10)
memory usage: 76.3 MB
Test_data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 50000 entries, 0 to 49999
Data columns (total 39 columns):
 #   Column             Non-Null Count  Dtype  
---  ------             --------------  -----  
 0   SaleID             50000 non-null  int64  
 1   name               50000 non-null  int64  
 2   regDate            50000 non-null  int64  
 3   model              50000 non-null  float64
 4   brand              50000 non-null  int64  
 5   bodyType           44890 non-null  float64
 6   fuelType           45598 non-null  float64
 7   gearbox            47287 non-null  float64
 8   power              50000 non-null  int64  
 9   kilometer          50000 non-null  float64
 10  notRepairedDamage  40372 non-null  float64
 11  regionCode         50000 non-null  int64  
 12  seller             50000 non-null  int64  
 13  offerType          50000 non-null  int64  
 14  creatDate          50000 non-null  int64  
 15  v_0                50000 non-null  float64
 16  v_1                50000 non-null  float64
 17  v_2                50000 non-null  float64
 18  v_3                50000 non-null  float64
 19  v_4                50000 non-null  float64
 20  v_5                50000 non-null  float64
 21  v_6                50000 non-null  float64
 22  v_7                50000 non-null  float64
 23  v_8                50000 non-null  float64
 24  v_9                50000 non-null  float64
 25  v_10               50000 non-null  float64
 26  v_11               50000 non-null  float64
 27  v_12               50000 non-null  float64
 28  v_13               50000 non-null  float64
 29  v_14               50000 non-null  float64
 30  v_15               50000 non-null  float64
 31  v_16               50000 non-null  float64
 32  v_17               50000 non-null  float64
 33  v_18               50000 non-null  float64
 34  v_19               50000 non-null  float64
 35  v_20               50000 non-null  float64
 36  v_21               50000 non-null  float64
 37  v_22               50000 non-null  float64
 38  v_23               50000 non-null  float64
dtypes: float64(30), int64(9)
memory usage: 14.9 MB

4.判断数据缺失和异常

1) 查看每列的存在nan情况
## 1) 查看每列的存在nan情况
Train_data.isnull().sum()
SaleID                   0
name                     0
regDate                  0
model                    0
brand                    0
bodyType             25380
fuelType             22490
gearbox              13513
power                    0
kilometer                0
notRepairedDamage    48536
regionCode               0
seller                   0
offerType                0
creatDate                0
price                    0
v_0                      0
v_1                      0
v_2                      0
v_3                      0
v_4                      0
v_5                      0
v_6                      0
v_7                      0
v_8                      0
v_9                      0
v_10                     0
v_11                     0
v_12                     0
v_13                     0
v_14                     0
v_15                     0
v_16                     0
v_17                     0
v_18                     0
v_19                     0
v_20                     0
v_21                     0
v_22                     0
v_23                     0
dtype: int64
Test_data.isnull().sum()
SaleID                  0
name                    0
regDate                 0
model                   0
brand                   0
bodyType             5110
fuelType             4402
gearbox              2713
power                   0
kilometer               0
notRepairedDamage    9628
regionCode              0
seller                  0
offerType               0
creatDate               0
v_0                     0
v_1                     0
v_2                     0
v_3                     0
v_4                     0
v_5                     0
v_6                     0
v_7                     0
v_8                     0
v_9                     0
v_10                    0
v_11                    0
v_12                    0
v_13                    0
v_14                    0
v_15                    0
v_16                    0
v_17                    0
v_18                    0
v_19                    0
v_20                    0
v_21                    0
v_22                    0
v_23                    0
dtype: int64

通过可视化直观了解哪些列存在 “nan”, 目的在于查看nan存在的个数大小:如果很小一般选择填充;如果使用lgb等树模型可以直接空缺,让树自己去优化;但如果nan存在的过多、可以考虑删掉。

# nan可视化
missing = Train_data.isnull().sum()
missing = missing[missing > 0]
missing.sort_values(inplace=True)
missing.plot.bar()

在这里插入图片描述

# 可视化看下缺省值
msno.matrix(Train_data.sample(250))

在这里插入图片描述

msno.bar(Train_data.sample(1000))

在这里插入图片描述

# 可视化看下缺省值
msno.matrix(Test_data.sample(250
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值