Skip to content

Instantly share code, notes, and snippets.

@erykml
Created February 11, 2019 22:27
Show Gist options
  • Select an option

  • Save erykml/a86adf47d1e76edbc7e5eedcf8efdaba to your computer and use it in GitHub Desktop.

Select an option

Save erykml/a86adf47d1e76edbc7e5eedcf8efdaba to your computer and use it in GitHub Desktop.
prediction1, bias1, contributions1 = ti.predict(rf, np.array([selected_df[0]]), joint_contribution=True)
prediction2, bias2, contributions2 = ti.predict(rf, np.array([selected_df[1]]), joint_contribution=True)
aggregated_contributions1 = utils.aggregated_contribution(contributions1)
aggregated_contributions2 = utils.aggregated_contribution(contributions2)
res = []
for k in set(aggregated_contributions1.keys()).union(
set(aggregated_contributions2.keys())):
res.append(([X_train.columns[index] for index in k] ,
aggregated_contributions1.get(k, 0) - aggregated_contributions2.get(k, 0)))
for lst, v in (sorted(res, key=lambda x:-abs(x[1])))[:10]:
print (lst, v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment