Skip to content

Instantly share code, notes, and snippets.

@egemenzeytinci
Created December 26, 2019 21:52
Show Gist options
  • Save egemenzeytinci/123059def8684b6063afffe2a8360c0a to your computer and use it in GitHub Desktop.
Save egemenzeytinci/123059def8684b6063afffe2a8360c0a to your computer and use it in GitHub Desktop.
def select(X):
selects = []
selector = SelectKBest(chi2, k='all').fit(X, y)
scores = selector.scores_
q3 = np.quantile(scores, 0.75)
q1 = np.quantile(scores, 0.25)
iqr = q3 - q1
threshold = q3 + 1.5 * iqr
for col, val in zip(X.columns, scores):
cond1 = val > threshold
cond2 = col in test_hot.columns or col in test.columns
if cond1 and cond2:
if col not in test_hot.columns:
test_hot.loc[:, col] = 0
selects.append(col)
return selects
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment