Skip to content

Instantly share code, notes, and snippets.

@gvyshnya
Created July 9, 2020 17:52
Show Gist options
  • Save gvyshnya/7349198e74b4c5fc6caad18ac150ff07 to your computer and use it in GitHub Desktop.
Save gvyshnya/7349198e74b4c5fc6caad18ac150ff07 to your computer and use it in GitHub Desktop.
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