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
import numpy as np | |
from scipy import stats | |
def pearsonr_ci(x,y,alpha=0.05): | |
''' calculate Pearson correlation along with the confidence interval using scipy and numpy | |
Parameters | |
---------- | |
x, y : iterable object such as a list or np.array | |
Input for correlation calculation |
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
from sklearn.feature_selection import SelectFromModel | |
from sklearn.linear_model import LogisticRegression | |
embeded_lr_selector = SelectFromModel(LogisticRegression(penalty="l1"), max_features=num_feats) | |
embeded_lr_selector.fit(X_norm, y) | |
embeded_lr_support = embeded_lr_selector.get_support() | |
embeded_lr_feature = X.loc[:,embeded_lr_support].columns.tolist() | |
print(str(len(embeded_lr_feature)), 'selected features') |
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
from sklearn.feature_selection import RFE | |
from sklearn.linear_model import LogisticRegression | |
rfe_selector = RFE(estimator=LogisticRegression(), n_features_to_select=num_feats, step=10, verbose=5) | |
rfe_selector.fit(X_norm, y) | |
rfe_support = rfe_selector.get_support() | |
rfe_feature = X.loc[:,rfe_support].columns.tolist() | |
print(str(len(rfe_feature)), 'selected features') |
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
from sklearn.feature_selection import SelectKBest | |
from sklearn.feature_selection import chi2 | |
from sklearn.preprocessing import MinMaxScaler | |
X_norm = MinMaxScaler().fit_transform(X) | |
chi_selector = SelectKBest(chi2, k=num_feats) | |
chi_selector.fit(X_norm, y) | |
chi_support = chi_selector.get_support() | |
chi_feature = X.loc[:,chi_support].columns.tolist() | |
print(str(len(chi_feature)), 'selected features') |