Created
December 26, 2019 21:52
-
-
Save egemenzeytinci/123059def8684b6063afffe2a8360c0a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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