特征选择的主要作用是:降维,减少特征数量,防止过拟合,增强模型的泛化能力。

1、变异系数(标准差/均值)

import numpy as np
np.std(x)/np.mean(x)

2、皮尔逊相关系数(线性相关)

from scipy.stats import pearsonr
pearsonr(x, y)

3、互信息

from minepy import MINE
m = MINE()
m.compute_score(x, y)
print(m.mic())

4、线性拟合系数

5、L1(Lasso)或者L2(Ridge)正则化

6、树模型

7、交叉验证

8、卡方检验

from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
model1 = SelectKBest(chi2, k=2)#卡方检验
model1.fit_transform(x, y)
score = zip(feature_columns, model1.scores_)#置信度越高越好
value = zip(feature_columns, model1.pvalues_)#p值越小越好
score = sorted(score, key=lambda x: x[1], reverse=True)
value = sorted(value, key=lambda x: x[1], reverse=False)
print '置信度:', score
print 'p值:', value