Datawhale -数据挖掘 - task2:特征衍生+特征挑选

任务说明

特征衍生
特征挑选:分别用IV值和随机森林等进行特征选择
……以及你能想到特征工程处理

特征衍生

特征衍生:利用个人(专家)经验来提取出数据里对结果影响更大的特征,往往是原有数据特征字段通过加减乘除等操作生成新的字段,这些字段在结合一些线性算法做训练的时候往往能起到提升模型效果的作用。举例,用户点外卖,同一家店A,统计一个星期内用户在这家店的购买次数,甚至统计一个月时间范围内,这样的时间周期特征就可以被认为是衍生特征。具体是怎么来的呢?拍脑袋想出来的,有些是具有统计含义的,有些就靠自己摸索,所以一开始就说是经验得来的,你要说有技巧没有,那就是多参加比赛,看看别人怎么提取特征,多自己动手探索,

import pandas as pd
import numpy as np

dataPath = "D:\\Data\\dataAnalyse\\"
dataFile = "data.csv"
data = pd.read_csv(dataPath+dataFile,encoding='gbk')

label = data.columns
print('特征名=',label)

结果:

特征名= Index(['Unnamed: 0', 'custid', 'trade_no', 'bank_card_no',
       'low_volume_percent', 'middle_volume_percent',
       'take_amount_in_later_12_month_highest',
       'trans_amount_increase_rate_lately', 'trans_activity_month',
       'trans_activity_day', 'transd_mcc', 'trans_days_interval_filter',
       'trans_days_interval', 'regional_mobility', 'student_feature',
       'repayment_capability', 'is_high_user', 'number_of_trans_from_2011',
       'first_transaction_time', 'historical_trans_amount',
       'historical_trans_day', 'rank_trad_1_month', 'trans_amount_3_month',
       'avg_consume_less_12_valid_month', 'abs',
       'top_trans_count_last_1_month', 'avg_price_last_12_month',
       'avg_price_top_last_12_valid_month', 'reg_preference_for_trad',
       'trans_top_time_last_1_month', 'trans_top_time_last_6_month',
       'consume_top_time_last_1_month', 'consume_top_time_last_6_month',
       'cross_consume_count_last_1_month',
       'trans_fail_top_count_enum_last_1_month',
       'trans_fail_top_count_enum_last_6_month',
       'trans_fail_top_count_enum_last_12_month',
       'consume_mini_time_last_1_month',
       'max_cumulative_consume_later_1_month',
       'max_consume_count_later_6_month',
       'railway_consume_count_last_12_month',
       'pawns_auctions_trusts_consume_last_1_month',
       'pawns_auctions_trusts_consume_last_6_month',
       'jewelry_consume_count_last_6_month', 'status', 'source',
       'first_transaction_day', 'trans_day_last_12_month', 'id_name',
       'apply_score', 'apply_credibility', 'query_org_count',
       'query_finance_count', 'query_cash_count', 'query_sum_count',
       'latest_query_time', 'latest_one_month_apply',
       'latest_three_month_apply', 'latest_six_month_apply', 'loans_score',
       'loans_credibility_behavior', 'loans_count', 'loans_settle_count',
       'loans_overdue_count', 'loans_org_count_behavior',
       'consfin_org_count_behavior', 'loans_cash_count',
       'latest_one_month_loan', 'latest_three_month_loan',
       'latest_six_month_loan', 'history_suc_fee', 'history_fail_fee',
       'latest_one_month_suc', 'latest_one_month_fail', 'loans_long_time',
       'loans_latest_time', 'loans_credit_limit', 'loans_credibility_limit',
       'loans_org_count_current', 'loans_product_count', 'loans_max_limit',
       'loans_avg_limit', 'consfin_credit_limit', 'consfin_credibility',
       'consfin_org_count_current', 'consfin_product_count',
       'consfin_max_limit', 'consfin_avg_limit', 'latest_query_day',
       'loans_latest_day'],
      dtype='object')

上述特征中就有很多就是衍生后的特征,比如:latest_one_month_suc、latest_one_month_fail、latest_six_month_loan,这些都是处理好的特征,

IV值(信息量)

IV的全称是Information Value,中文意思是信息价值,或者信息量。主要用来对输入变量进行编码和预测能力评估。
我们在用逻辑回归、决策树等模型方法构建分类模型时,经常需要对自变量进行筛选。比如我们有200个候选自变量,通常情况下,不会直接把200个变量直接放到模型中去进行拟合训练,而是会用一些方法,从这200个自变量中挑选一些出来,放进模型,形成入模变量列表。那么我们怎么去挑选入模变量呢?

挑选入模变量过程是个比较复杂的过程,需要考虑的因素很多,比如:变量的预测能力,变量之间的相关性,变量的简单性(容易生成和使用),变量的强壮性(不容易被绕过),变量在业务上的可解释性(被挑战时可以解释的通)等等。但是,其中最主要和最直接的衡量标准是变量的预测能力。

“变量的预测能力”这个说法很笼统,很主观,非量化,在筛选变量的时候我们总不能说:“我觉得这个变量预测能力很强,所以他要进入模型”吧?我们需要一些具体的量化指标来衡量每自变量的预测能力,并根据这些量化指标的大小,来确定哪些变量进入模型。IV就是这样一种指标,他可以用来衡量自变量的预测能力。类似的指标还有信息增益、基尼系数等等。

这个IV值依赖一个WOE值,这里有点复杂,找个时间好好研究一下。可以参考博客。

随机森林

from sklearn.ensemble import RandomForestClassifier
y_train = data['status']
x_train = data.drop(['status'],axis =1)
forest = RandomForestClassifier(n_estimators=10000, random_state=0,n_jobs=1)
forest.fit(x_train, y_train)
importance = forest.feature_importances_
imp_result = np.argsort(importance)[::-1]

for i in range(data.shape[1]):
    print("%2d. %-*s %f"%(i+1, 30, label[i], importance[imp_result[i]]))

参考博客

[特征工程系列三]显性特征的衍生
特征衍生 -1
IV值的计算及使用

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值