【问题标题】:Feature selection using statistical model使用统计模型进行特征选择
【发布时间】:2020-01-13 23:08:22
【问题描述】:

问题陈述

我正在解决一个问题,我必须预测客户是否会选择贷款。我已将所有可用的数据类型(对象、整数)转换为整数,现在我的数据如下所示。

突出显示的列是我的目标列,其中

0 表示

1 表示

这个数据集中有47个独立的列。

我想针对我的 Target 列对这些列进行特征选择

我从 Z-test

开始
import numpy as np
import scipy.stats as st
import scipy.special as sp


def feature_selection_pvalue(df,col_name,samp_size=1000):
    relation_columns=[]
    no_relation_columns=[]
    H0='There is no relation between target column and independent column'
    H1='There is a relation between target column and independent column'
    sample_data[col_name]=df[col_name].sample(samp_size)
    samp_mean=sample_data[col_name].mean()
    pop_mean=df[col_name].mean()
    pop_std=df[col_name].std()
    print (pop_mean)
    print (pop_std)
    print (samp_mean)
    n=samp_size
    q=.5
    #lets calculate z
    #z = (samp_mean - pop_mean) / np.sqrt(pop_std*pop_std/n)
    z = (samp_mean - pop_mean) / np.sqrt(pop_std*pop_std / n)
    print (z)
    pval = 2 * (1 - st.norm.cdf(z))
    print ('p values is==='+str(pval))
    if pval< .05 :
        print ('Null hypothesis is Accepted for col ---- >'+H0+col_name)

        no_relation_columns.append(col_name)
    else:
        print ('Alternate Hypothesis is accepted -->'+H1)
        relation_columns.append(col_name)
        print ('length of list ==='+str(len(relation_columns)))


    return relation_columns,no_relation_columns

当我运行这个函数时,我总是得到不同的结果

for items in df.columns:
    relation,no_relation=feature_selection_pvalue(df,items,5000)

我的问题是

  1. 高于 z-Test 是进行特征选择的可靠方法,但每次结果都不同
  2. 在这种情况下,进行特征选择的更好方法是什么,如果可能,请提供示例

【问题讨论】:

    标签: machine-learning statistics feature-extraction feature-selection


    【解决方案1】:

    在这种情况下,进行特征选择的更好方法是什么? 如果可能的话,提供一个例子

    你可以使用scikit 吗?他们提供了很多示例和可能性来选择您的功能: https://scikit-learn.org/stable/modules/feature_selection.html

    如果我们看第一个(方差阈值):

    from sklearn.feature_selection import VarianceThreshold
    X = df[['age', 'balance',...]] #select your columns
    sel = VarianceThreshold(threshold=(.8 * (1 - .8)))
    X_red = sel.fit_transform(X)
    

    这只会保留有一些差异的列,而不是只有相同的值。

    【讨论】:

      猜你喜欢
      • 2018-05-23
      • 2013-08-15
      • 2016-03-16
      • 1970-01-01
      • 2022-07-27
      • 2014-11-05
      • 2014-02-05
      • 1970-01-01
      相关资源
      最近更新 更多