zoukankan      html  css  js  c++  java
  • 数据预处理


    • 查看数据信息
    • 数据异常
    • 空数据
    • 数据不均衡
    • 数据归一化
    • 大量数据

    预处理方法


    数据引入

    • csv
    • html, html、sax、dom 解析器
    • xml
    • databases,pyodbc
    • json
    • pdf, pdfminer

    查看数据信息

    DataFrame的基础属性

    DataFrame的基础属性

    df.shape ——行数 列数
    df.dtypes——列数据类型
    df.ndim ——数据维度
    df.index——行索引
    df.columns——列索引
    df.values——对象值,二维ndarray数组


    DataFrame 整体情况

    df.head(10)——显示前10行,默认是5行
    df.tail()——显示末尾几行,默认是5
    df.info()——相关系数,如行数,列数,列索引、列非空值个数,列类型,内存占用
    df.describe()——快速统计结果,计数、均值、标准差、最大值、四分数、最小值

    data.info() 
    '''
    <class 'pandas.core.frame.DataFrame'>
    RangeIndex: 3463 entries, 0 to 3462
    Data columns (total 20 columns):
     #   Column         Non-Null Count  Dtype  
    ---  ------         --------------  -----  
     0   subscriberID   3463 non-null   float64
     1   churn          3463 non-null   float64
     2   gender         3463 non-null   float64
     3   AGE            3463 non-null   float64
     4   edu_class      3463 non-null   float64
     5   incomeCode     3463 non-null   float64
     6   duration       3463 non-null   float64
     7   feton          3463 non-null   float64
     8   peakMinAv      3463 non-null   float64
     9   peakMinDiff    3463 non-null   float64
     10  posTrend       3463 non-null   float64
    ...
    dtypes: float64(20)
    memory usage: 541.2 KB
    '''
    
    data.describe()
    
    subscriberID churn gender AGE edu_class
    count 3.463000e+03 3463.000000 3463.000000 3463.000000 3463.000000
    mean 7.462747e+07 0.442969 0.497834 30.677447 0.953797
    std 2.117726e+06 0.496808 0.500068 14.037055 0.860355
    min 1.916496e+07 0.000000 0.000000 9.000000 0.000000
    25% 7.480676e+07 0.000000 0.000000 18.000000 0.000000
    50% 7.488497e+07 0.000000 0.000000 28.000000 1.000000

    pd.value_counts 查看数值各有多少个

    count_classes = pd.value_counts(data['Class'], sort = True).sort_index()
    

    数据不均衡


    缺失值

    1. 删除数据
    2. 填充为 中位数、众数、平均数

    异常值

    四分位法,识别离群点


    大量数据

    降低数据类型

    int64 -> int32


    One-Hot 独热编码

    将文本分类数据转化 数值


    归一化 & 标准化


    其他常用代码

    rdd 中忽略第一行

    headers = data1.first()
    data2 = data1.filter(lambda line:line != headers)
    data2.take(4)
    
    
    

    取出特征数据

    X = hdata.loc[:,:'cnt']
    y = hour['cnt']
    

    数据集切分

    from sklearn.model_selection import train_test_split
    X_train, X_test, y_train, y_test = train_test_split(X, y)
    
  • 相关阅读:
    Linux tmux 工具
    HTML 注释
    HTML 引用
    HTML 格式化
    /etc/services
    Linux ss 命令
    Python cookielib 模块
    爬取需要登录的页面
    hasattr() 、getattr() 、setattr()
    爬取文本
  • 原文地址:https://www.cnblogs.com/fldev/p/14360137.html
Copyright © 2011-2022 走看看