Created
October 16, 2019 05:38
-
-
Save seahrh/be4469e8a1130597d3721c51fd6775cd to your computer and use it in GitHub Desktop.
Permutation importance function
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
def permutation_importance(X, y, model): | |
perm = {} | |
y_true = model.predict_proba(X)[:,1] | |
baseline= roc_auc_score(y, y_true) | |
for cols in X.columns: | |
value = X[cols] | |
X[cols] = np.random.permutation(X[cols].values) | |
y_true = model.predict_proba(X)[:,1] | |
perm[cols] = roc_auc_score(y, y_true) - baseline | |
X[cols] = value | |
return perm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment