Created
July 9, 2020 17:52
-
-
Save gvyshnya/7349198e74b4c5fc6caad18ac150ff07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# Define dictionary to store our rankings | |
ranks = {} | |
# Create our function which stores the feature rankings to the ranks dictionary | |
def ranking(ranks, names, order=1): | |
minmax = MinMaxScaler() | |
ranks = minmax.fit_transform(order*np.array([ranks]).T).T[0] | |
ranks = map(lambda x: round(x,2), ranks) | |
return dict(zip(names, ranks)) | |
# Do FRE feature importance scoring - | |
# stop the search when only the last feature is left | |
rfe = RFE(estimator, n_features_to_select=1, verbose =3 ) | |
rfe.fit(X, y) | |
ranks["RFE_RF"] = ranking(list(map(float, rfe.ranking_)), colnames, order=-1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment