(天池)零基础入门数据挖掘-心跳信号分类预测总结笔记(三)

1、方差选择法
使用方差选择法,先要计算各个特征的方差,然后根据阈值,选择方差大于阈值的特征。
函数:sklearn.feature_selection.VarianceThreshold
用法:from sklearn.feature_selection
import VarianceThreshold
#方差选择法,返回值为特征选择后的数据
#参数threshold为方差的阈值
VarianceThreshold(threshold=3).fit_transform(iris.data)

2、卡方选择法
经典的卡方检验是检验定性自变量对定性因变量的相关性。
函数:sklearn.feature_selection.SelectKBest
用法:from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
#选择K个最好的特征,返回选择特征后的数据
SelectKBest(chi2, k=2).fit_transform(iris.data, iris.target)
3、递归特征消除法
递归消除特征法使用一个基模型来进行多轮训练,每轮训练后,消除若干权值系数的特征,再基于新的特征集进行下一轮训练。
函数:sklearn.feature_selection.RFE
用法:from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
#递归特征消除法,返回特征选择后的数据
#参数estimator为基模型
#参数n_features_to_select为选择的特征个数
RFE(estimator=LogisticRegression(), n_features_to_select=2).fit_transform(iris.data, iris.target)

4、基于惩罚项的特征选择法
使用带惩罚项的基模型,除了筛选出特征外,同时也进行了降维。
函数:sklearn.feature_selection .SelectFromModel
用法:from sklearn.feature_selection
import SelectFromModel
from sklearn.linear_model
import LogisticRegression
#带L1惩罚项的逻辑回归作为基模型的特征选择SelectFromModel(LogisticRegression(penalty=“l1”, C=0.1)).fit_transform(iris.data, iris.target)

5、基于树模型的特征选择法
树模型中GBDT也可用来作为基模型进行特征选择。
函数:sklearn.preprocessing.Imputer
用法:from sklearn.feature_selection
import SelectFromModel
from sklearn.ensemble
import GradientBoostingClassifier
#GBDT作为基模型的特征选择
SelectFromModel(GradientBoostingClassifier()).fit_transfor:m(iris.data, iris.target)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值