Skip to content

Instantly share code, notes, and snippets.

@seahrh
Created October 16, 2019 05:38
Show Gist options
  • Save seahrh/be4469e8a1130597d3721c51fd6775cd to your computer and use it in GitHub Desktop.
Save seahrh/be4469e8a1130597d3721c51fd6775cd to your computer and use it in GitHub Desktop.
Permutation importance function
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