<jupyter_start><jupyter_text>一个简单的分享> test<jupyter_code>import pandas as pd
import numpy as np
from feature_selector import FeatureSelector
import warnings
warnings.filterwarnings('ignore')
dataset = pd.read_csv("/data_hdd/Kaggle_data/competitions/home-credit-default-risk/application_train.csv")
labels = dataset["TARGET"]
dataset.head()<jupyter_output><empty_output><jupyter_text>我们在使用 FS 的时候记得先将 target 从数据集中 drop 掉<jupyter_code>dataset = dataset.drop(columns=['TARGET'])
fs_instance = FeatureSelector(data=dataset, labels=labels)<jupyter_output><empty_output><jupyter_text>让我们来看看原生的数据集中有多少是共线性的特征$$x^2+y^2=1$$<jupyter_code>fs_instance.identify_collinear(correlation_threshold=0.975)
fs_instance.plot_collinear()<jupyter_output>23 features with a correlation magnitude greater than 0.97.<jupyter_text>随后我们用 LightGBM 快速跑一个简易的baseline，这里需要注意所有的类别变量，会被做 one hot encoding<jupyter_code>fs_instance.identify_zero_importance(task='classification', eval_metric='auc', n_iterations=3, early_stopping=True)
one_hot_features = fs_instance.one_hot_features
base_features = fs_instance.base_features
print('There are {} original features'.format(len(base_features)))
print('There are {} one hotencoded features'.format(len(one_hot_features)))
fs_instance.plot_feature_importances(threshold=0.9, plot_n=5)<jupyter_output>There are 121 original features
There are 140 one hotencoded features
{'fraction_non_alphanumeric': 0.10224800580130529, 'fraction_numerical': 0.01595358955765047, 'mean_word_length': 12.018867924528301, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '190347', 'license': 'MIT', 'n_tokens_mistral': 517, 'n_tokens_neox': 508, 'n_words': 73, 'path': 'basic_features.ipynb', 'repo_name': 'ailurus1991/wide_deep_keras', 'size': '1379'}