Exploratory Data Analysis
0.忽略警告
导入warnings包,利用过滤器来实现忽略警告语句
1 | import warnings |
1.简单观察数据
1 | data.head().append(data.tail()) |
2.观察数据形状
1 | data.shape |
3.总览数据概况
观察均值、极值、数量等
1 | data.describe() |
4.缺失值检测
1 | data.isnull().sum() |
5.nan可视化
1 | missing = data.isnull().sum() |
6.缺失值填充
这里采用众数填充
1 | data = data.fillna(data.mode().iloc[0,:]) |
7.检查数据类型
1 | data.info() |
8.异常值处理
以天池二手车价格预测数据集为例,其notRepairedDamage为字符串类型,需要转换成数值类型;异常值’-‘,用众数进行填充
1 | data.notRepairedDamage.replace('-', 0, inplace=True) |
9.离群点处理
通过箱线图判断离群点,以’power’, ‘v_11’, ‘v_12’, ‘v_13’, ‘v_14’为例
1 | plt.figure(figsize=(20,10)) |
截断离群值
1 | data['power'][data['power']>600] = 600 |
10.压缩数据
判断数据极值,用np.iinfo(np.int8)
获取int8的范围,尽量将数据用更少的字节存储
1 | def MemoryReduce(data): |
11.倾斜值处理
1 | # 读取每列不同取值的个数 |
1
2
3
4
5
6
7
8 >SaleID 200000
>name 128660
>regDate 3898
>model 248
>seller 2
>offerType 1
>creatDate 106
>dtype: int64
如上所示,seller 特征几乎均为 0,offerType 所有特征均为 0,存在严重的数据倾斜,对模型训练毫无帮助,删去
删除特征
1 | data.drop(['offerType', 'seller'], axis=1, inplace=True) |
12.预测值总体分布曲线
无界约翰逊分布、正态分布、对数正态分布
1 | import scipy.stats as st |
13.生成数据分析报告
1 | import pandas_profiling |