<jupyter_start><jupyter_text>RFE<jupyter_code>from sklearn.feature_selection import RFE
from sklearn.tree import DecisionTreeClassifier
from sklearn.svm import SVR
estimator = SVR(kernel="linear")
# define RFE
rfe = RFE(estimator, n_features_to_select=4)
# fit RFE
selector=rfe.fit(data_trans, y)
!cd
selector.support_
df
# summarize all features
for i in range(data_trans.shape[1]):
  print('Column: %d,  Rank: %d' % (i,  rfe.ranking_[i]))
df1=pd.DataFrame(data_trans)<jupyter_output><empty_output><jupyter_text>MinMaxScaler<jupyter_code>from sklearn.preprocessing import MinMaxScaler
trans = MinMaxScaler()
data.shape
X_norm = trans.fit_transform(data)
df_norm = pd.DataFrame(X_norm)
df_norm.describe()
df.describe()<jupyter_output><empty_output><jupyter_text>StandardScaler<jupyter_code>from sklearn.preprocessing import StandardScaler
sc=StandardScaler()
df_sc=sc.fit_transform(data)
df_trsfrom_sc=pd.DataFrame(df_sc)
df_trsfrom_sc.describe().round()
data<jupyter_output><empty_output><jupyter_text>PCA<jupyter_code>from sklearn.decomposition import PCA
data_trans.shape
# define the transform
trans = PCA(n_components=4)
# transform the data
X_dim = trans.fit_transform(data_trans)
# summarize data after the transform
print(X_dim[:3, :])<jupyter_output>[[-1.57322001 -1.79801078  0.25030993 -0.52975036]
 [-0.53149069 -1.62758675  0.86777683 -0.13298349]
 [ 1.02701877 -1.04999402  0.08889292 -0.26020156]]<jupyter_text>Regression Feature Selection<jupyter_code>from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import f_regression
fs = SelectKBest(score_func=f_regression, k=4)
data_trans.shape
y.shape
# apply feature selection
X_selected = fs.fit_transform(data_trans, y)
print(X_selected.shape)<jupyter_output>(252, 4)
{'fraction_non_alphanumeric': 0.11085844229675952, 'fraction_numerical': 0.06708357021034679, 'mean_word_length': 8.312169312169312, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '654649', 'license': 'MIT', 'n_tokens_mistral': 744, 'n_tokens_neox': 669, 'n_words': 114, 'path': 'SQL/python_db_rfe.ipynb', 'repo_name': 'devming0322/2021-K-Digital-Training', 'size': '1759'}