Machine Learning: data preparation and engineering features

For data mining, data preparation phase is the main feature project.

 

 Data and characteristics determine the upper limit of the model predictions, and the algorithm just approaching this limit.

 

Good features should be concise, which makes the model easier and more accurate.

 

 

A feature configured

1. 'common extraction methods

Wherein the text data extraction

Bag of words vector way: statistical frequency

 

 Extracting feature image data

RGB pixels

User behavior feature extraction

 

 

 

Feature Extraction Summary:

  • Require highly correlated with the target design features:

    This feature is useful for the prediction target

    If useful How important is this feature

    Whether information of this feature in other features reflect too heavy

  • Feature requires knowledge, intuition and a certain mathematical areas of expertise
  • The initial characteristic extracting feature also subsequent conversion process, and then into the model algorithm
  • Design features and extraction requires constant iterative verification is a very time-consuming work

 

2.RFM

Customer relationship (CRM) field, three user portray magic indicators:

  • Recent long (Recency) interval when a consumer
  • Consumption Frequency (Frequency)
  • The amount of consumption (Monetary)

 

RFM analysis methods are called quintile law

The number of individual cut into 5 aliquots RFM interval, then a combination of a cube RFM

125 grid

 

 R smaller the better, FM bigger the better

R is, the larger the grade, for the unified so RMF level the better

Therefore, the user level range is 111-555

 

RFM value: user segment

111-555 a total of 125 groups, more, you can do some consolidation

The different combinations of values ​​of RFM, users can be divided into different groups to develop differentiation strategy

 

 

RFM value: customer value and respond evaluate marketing

 

 

 

Second, the conversion characteristics

1. Continuous process variable dimensionless

The scale of the conversion data of different specifications to the same standard scale

purpose:

  • Allows dimensionless characteristic values ​​are not the same dimension may be compared: e.g. height (cm), weight (kg)
  • After the non-dimensional model of convergence will speed up (running faster)
  • The results of some of the non-dimensional model of the impact is relatively large, such as clustering model, nondimensionalization would be better based on the distance of some models

 

Common Undimensionalization - Standardization

Effect: the original continuous variable into a mean of 0 and standard deviation 1 to variables

${x}'=\frac{x-\bar{x}}{\delta }$

 Common Undimensionalization - scaling Interval Method

效果:把原始的连续变量转换为范围在a-b之间的变量,常见的a=0,b=1

${x}'=\frac{x-\min(x)}{\max(x)-\min(x) }$

 

2.连续变量数据变换

数据变换:通过函数变换改变原数据的分布

目的:

  • 变换后更便捷地发现数据之间的关系:从没有关系变成有关系
  • 很多数据呈现严重的偏态分布(很多偏小的值聚集在一起),变换后差异可以拉开
  • 让数据更符合模型理论所需要的假设,然后对其分析,例如变换后数据呈现正态分布

 

 常用的数据变换方法

  • log变换 x=ln(x)
  • box-cox变换,自动寻找最佳正态分布变换函数的方法

 

 

3.连续变量离散化

把连续型的数值切割为少数的一些区间,例如年龄值切割为5个年龄段

目的:

  • 方便探索数据分布和相关性,例如直方图,交叉表
  • 离散化后的特征对异常数据有很强的鲁棒性:减少异常数据对模型的影响
  • 离散化后可以进行特征交叉组合,由M+N个特征变量变为M*N个特征变量
  • 特征离散化后,模型会更稳定
  • 特征离散化后,简化了模型复杂度,降低了过拟合风险
  • 一些模型(关联模型)要求输入特征是离散的

 

离散化方法:

非监督离散化方法

 

 

有监督的离散化:决策树

 

 

一种特殊的离散化:二值化

 

 一种特殊的离散化:Rounding(取整)

 

4.类别变量编码

把类别型变量编码成数值型的变量

目的:

  • 很多机器学习算法无法处理类别型变量,必须转换为数值型变量
  • 一定程度上起到了扩充特征的作用(构造了新的特征)

 

one-hot编码

 

 Counting Encoding

用类别的频数来编码,也可以对频数去量纲化(秩序,归一化等)

 

 Target Encoding

用目标变量(二分类)中的某一类的比例来编码

 

 

5.日期型变量处理

 

 

6.缺失值处理

缺失值原因

 

 处理方法

 

 

7.特征组合

目的:通过特征组合构造出更多/更好的特征,提示模型精度

 

 组合让特征更加精细,反映了原始多个特征之间的交互关系。

 

特征组合的方法

 

 示例

 

 

三、数据降维

在尽量少减少信息量的前提下,采用某种映射方法(函数),把原来的高维(变量多)数据映射为低维数据(变量少)

 

 降维原因:

  • 维数灾难:高维情况下容易发生模型的过拟合(泛化能力弱)
  • 特征之间有明显的自相关的时候,也要考虑降维,因为自相关会让模型效果变差
  • 降维可以对数据中的有效信息进行综合提取,并去除一些无用的噪音信息
  • 降维后降低模型复杂度,减少模型训练时间
  • 降维之后可以对数据进行可视化分析

 

维数灾难

 

 维数灾难原因

当特征值(空间)个数趋向无限大时,样本密度非常稀疏,训练样本被分错的可能性趋向于零

 

 降维后发生什么?

线性模型可能精确度会下降,但是也会避免出现过拟合现象

 

 避免维度灾难的一个方法是增加样本量

样本密度:样本数/特征值个数;当增加维度时,保持样本密度不变的方法就是增加样本量

 

 

常用降维方法

 

 

主成分分析

通过某种线性投影,将高维数据映射到低维空间中表示,并期望在所投影的维度上数据方差最大。使用较少的数据维度,尽量保留住较多的数据信息。

 

 PCA操作流程

 

 

线性判别分析法

 

 PCA与LDA

 

 实验结果

 

 

总结:

  • 如果研究的问题有目标变量(类别型)

    优先使用LDA来降维

    可以使用PCA做小幅度的降维去噪声,然后再使用LDA降维

  • 如果研究的问题没有目标变量

    优先使用PCA来降维

 

四、特征选择

特征选择与降维

 

 特征选择原因:

  • 提高预测准确性
  • 构造更快,消耗更低的预测模型
  • 能够对模型有更好的理解和解释

 

特征选择的方法

 

 

单特征重要性评估

过滤方法

 

苹果onNet_month与Flag(目标)指标的相关性

 

 

信息值(IV)

 

 变量重要性可视化:趋势分析

 

 

 

 

更多指标

 

Guess you like

Origin www.cnblogs.com/aidata/p/11620888.html