<jupyter_start><jupyter_text>Univariate Selection<jupyter_code># Feature Extraction with Univariate Statistical Tests (Chi-squared for classification)
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
# select 4 best features 
test = SelectKBest(score_func=chi2, k=4) 
# fit 
fit = test.fit(X, y)
print(fit.scores_) 
features = fit.transform(X)
features<jupyter_output>[ 111.51969064 1411.88704064   17.60537322   53.10803984 2175.56527292
  127.66934333    5.39268155  181.30368904]<jupyter_text>Recursive Feature Elimination<jupyter_code>from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
rfe = RFE(model, 3)
fit = rfe.fit(X, y)
fit.n_features_
fit.support_
fit.ranking_<jupyter_output><empty_output><jupyter_text>Principal Component Analysis<jupyter_code>from sklearn.decomposition import PCA
pca = PCA(n_components=3) 
fit = pca.fit(X)
fit.explained_variance_ratio_
fit.components_<jupyter_output><empty_output><jupyter_text>Feature Importance<jupyter_code>from sklearn.ensemble import ExtraTreesClassifier
model = ExtraTreesClassifier()
model.fit(X,y)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08659450457951708, 'fraction_numerical': 0.07660283097418817, 'mean_word_length': 8.106060606060606, 'pattern_counts': {'":': 0, '<': 16, '<?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': '467189', 'license': 'MIT', 'n_tokens_mistral': 500, 'n_tokens_neox': 427, 'n_words': 80, 'path': 'AML/04-Feature Selection .ipynb', 'repo_name': 'hossainlab/ML', 'size': '1201'}