Skip to main content

随机递归特征消除

1、概述

为了提高模型性能,我们通常会给数据进行降维,一种有效的方法就是删掉一些无用的或者无效的特征,以达到8。递归特征消除就是这样方法之一,即通过不断训练模型,每次训练都将重要性最小的特征删除,直到满足停止条件。

这是一种贪心策略,不断删除最不重要的特征并不能保证一定能够获得最优子集,一种有效的方式是在删除特征的时候加入一些随机因素。

随机递归特征消除在递归特征消除的过程中加入了随机因子,随机因子用于控制当前特征删除是执行随机删除还是将最不重要的特征删除,当执行随机特征删除时,将随机删除一个特征,每个特征被删除的概率不同,越重要的特征具有越小的被删除概率,其中特征重要性有模型的coef_属性或feature_importances_属性决定,其值做了取绝对值处理以防止权重为负,导致负概率的发生。

2、用法

from feature_selectors.RFE import RandomRFE
import pandas as pd
from sklearn.model_selection import train_test_split

df = pd.read_csv('your_datasets_path.txt')
X = df.drop(columns=['label'])
y = df['label']
X_train,X_test,y_train,y_test = train_test_split(X,y)

# 构建一个选择器实例,其他参数请参考请help一下,代码有注释。 
fs = RandomRFE(percent_of_random=0.1)
selected_feature = fs.auto_select(X_train,y_train)

3、后续

其他特征选择方法,后续陆续加入,争取做个特性选择器,欢迎大神指正,并完善特征选择器,方便你我他!

Release files for random-RFE 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for random-RFE 0.1.0
File Size Uploaded
random_RFE-0.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for random-RFE 0.1.0
File Interpreter ABI Platform
random_RFE-0.1.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size:8.8 kB

Release files / random_RFE-0.1.0.tar.gz

Download URL random_RFE-0.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c3d908a0b5f8d65343d86d35a85461a6845a53735d90bd0243591035175438e3
BLAKE2b-256 checksum
How to use checksums
ea46a856ddba5c71585c7bde136c9a6bfa9953eeeda655caf1eae0d339ce436a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release files / random_RFE-0.1.0-py2.py3-none-any.whl

Download URL random_RFE-0.1.0-py2.py3-none-any.whl
Size 4.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
44a61cf36a9e5d4c168705a1db03dd6b20b0171a1fa8e6b2abaca88741996b07
BLAKE2b-256 checksum
How to use checksums
e51840d1cecf5442aa14b8a57a2a81873c383d016bb730453e9557f4bb3c8620
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page